#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#include<set>
#define ll long long
using namespace std;
set<pair<int,int>>s;
set<pair<int,int>>a;
int delete_turn(){
int x,y;
int cnt=0;
set<pair<int,int>>temp;
for(auto p : a){
x=p.first;
y=p.second;
if((!a.count({x-1,y}) && !a.count({x+1,y}))||(!a.count({x,y-1}) && !a.count({x,y+1}))){
//a.erase({x,y});
temp.insert({x,y});
++cnt;
}
}
for(auto p : temp){
a.erase(p);
}
return cnt;
}
int solve(){
int cur = delete_turn();
int cnt = cur;
while(cur!=0){
cur=delete_turn();
cnt+=cur;
}
return cnt;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);cout.tie(NULL);
int n,m,k,q,x,y;
cin>>n>>m>>k>>q;
for(int i = 0;i<k;++i){
cin>>x>>y;
s.insert({x,y});
}
for(int Q = -1;Q<q;++Q){
if(Q!=-1){
cin>>x>>y;
if(s.count({x,y})){
s.erase({x,y});
}
else{
s.insert({x,y});
}
}
a=s;
cout<<solve()<<"\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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | #include<iostream> #include<vector> #include<algorithm> #include<utility> #include<set> #define ll long long using namespace std; set<pair<int,int>>s; set<pair<int,int>>a; int delete_turn(){ int x,y; int cnt=0; set<pair<int,int>>temp; for(auto p : a){ x=p.first; y=p.second; if((!a.count({x-1,y}) && !a.count({x+1,y}))||(!a.count({x,y-1}) && !a.count({x,y+1}))){ //a.erase({x,y}); temp.insert({x,y}); ++cnt; } } for(auto p : temp){ a.erase(p); } return cnt; } int solve(){ int cur = delete_turn(); int cnt = cur; while(cur!=0){ cur=delete_turn(); cnt+=cur; } return cnt; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL); int n,m,k,q,x,y; cin>>n>>m>>k>>q; for(int i = 0;i<k;++i){ cin>>x>>y; s.insert({x,y}); } for(int Q = -1;Q<q;++Q){ if(Q!=-1){ cin>>x>>y; if(s.count({x,y})){ s.erase({x,y}); } else{ s.insert({x,y}); } } a=s; cout<<solve()<<"\n"; } return 0; } |
English