#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
unordered_set<LL> tab;
bool chk(pair<int, int> poz){
return (tab.contains(poz.first+(LL(poz.second)<<32)));
}
vector<pair<int, int>> klocki;
int ile_do_usuniecia(){
int w=0;
for(int i=0; i<klocki.size(); i++){
if(chk(klocki[i])){
if((!chk({klocki[i].first, klocki[i].second-1}) && !chk({klocki[i].first, klocki[i].second+1})) || (!chk({klocki[i].first-1, klocki[i].second}) && !chk({klocki[i].first+1, klocki[i].second}))){
w++;
tab.erase((klocki[i].first+(LL(klocki[i].second)<<32)));
if(chk({klocki[i].first, klocki[i].second-1})) klocki.push_back({klocki[i].first, klocki[i].second-1});
if(chk({klocki[i].first, klocki[i].second+1})) klocki.push_back({klocki[i].first, klocki[i].second+1});
if(chk({klocki[i].first-1, klocki[i].second})) klocki.push_back({klocki[i].first-1, klocki[i].second});
if(chk({klocki[i].first+1, klocki[i].second})) klocki.push_back({klocki[i].first+1, klocki[i].second});
}
}
}
return w;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, m, k, q=(cin>>n>>m>>k>>q, q), x, y;
vector<pair<int, int>> tru_klocki;
for(int i=0; i<k; i++){
cin>>x>>y; tab.insert(x+(LL(y)<<32));
tru_klocki.push_back({x, y});
}
klocki=tru_klocki;
cout<<ile_do_usuniecia()<<'\n';
for(int i=0; i<q; i++){
cin>>x>>y;
bool flag=true;
for(int i=0; i<tru_klocki.size(); i++){
if(tru_klocki[i].first==x && tru_klocki[i].second==y){
flag=false; tru_klocki.erase(tru_klocki.begin()+i);
}
}
if(flag) tru_klocki.push_back({x, y});
klocki=tru_klocki; tab.clear();
for(int i=0; i<klocki.size(); i++) tab.insert(klocki[i].first+(LL(klocki[i].second)<<32));
cout<<ile_do_usuniecia()<<'\n';
}
return 0;
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | #include <bits/stdc++.h> using namespace std; typedef long long LL; unordered_set<LL> tab; bool chk(pair<int, int> poz){ return (tab.contains(poz.first+(LL(poz.second)<<32))); } vector<pair<int, int>> klocki; int ile_do_usuniecia(){ int w=0; for(int i=0; i<klocki.size(); i++){ if(chk(klocki[i])){ if((!chk({klocki[i].first, klocki[i].second-1}) && !chk({klocki[i].first, klocki[i].second+1})) || (!chk({klocki[i].first-1, klocki[i].second}) && !chk({klocki[i].first+1, klocki[i].second}))){ w++; tab.erase((klocki[i].first+(LL(klocki[i].second)<<32))); if(chk({klocki[i].first, klocki[i].second-1})) klocki.push_back({klocki[i].first, klocki[i].second-1}); if(chk({klocki[i].first, klocki[i].second+1})) klocki.push_back({klocki[i].first, klocki[i].second+1}); if(chk({klocki[i].first-1, klocki[i].second})) klocki.push_back({klocki[i].first-1, klocki[i].second}); if(chk({klocki[i].first+1, klocki[i].second})) klocki.push_back({klocki[i].first+1, klocki[i].second}); } } } return w; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, m, k, q=(cin>>n>>m>>k>>q, q), x, y; vector<pair<int, int>> tru_klocki; for(int i=0; i<k; i++){ cin>>x>>y; tab.insert(x+(LL(y)<<32)); tru_klocki.push_back({x, y}); } klocki=tru_klocki; cout<<ile_do_usuniecia()<<'\n'; for(int i=0; i<q; i++){ cin>>x>>y; bool flag=true; for(int i=0; i<tru_klocki.size(); i++){ if(tru_klocki[i].first==x && tru_klocki[i].second==y){ flag=false; tru_klocki.erase(tru_klocki.begin()+i); } } if(flag) tru_klocki.push_back({x, y}); klocki=tru_klocki; tab.clear(); for(int i=0; i<klocki.size(); i++) tab.insert(klocki[i].first+(LL(klocki[i].second)<<32)); cout<<ile_do_usuniecia()<<'\n'; } return 0; } |
English