using namespace std; #include <bits/stdc++.h> int main() { int n,m,k,q; cin>>n>>m>>k>>q; bool t[n+2][m+2]; for(int i=0; i<=n+1; i++){ t[i][0]=0; } for(int i=0; i<=m+1; i++){ t[0][i]=0; } for(int i=0; i<k; i++){ int x,y; cin>>x>>y; t[x][y]=1; } bool tempt[n+2][m+2]; for(int i=0; i<=n+1; i++){ for(int j=0; j<=m+1; j++){ tempt[i][j]=t[i][j]; } } int tempvalue=0; int value=-1; while(value!=0){ tempvalue+=value; value=0; vector<pair<int, int>> changes; for(int i=1; i<=n; i++){ for(int j=1; j<=m; j++){ if((!t[i-1][j]&&!t[i+1][j])||(!t[i][j-1]&&!t[i][j+1])){ changes.push_back({i, j}); value++; } } } for(auto idx : changes){ t[idx.first][idx.second]=0; } } cout<<tempvalue<<'\n'; for(int o=0; o<q; o++){ int x,y; cin>>x>>y; for(int i=0; i<=n+1; i++){ for(int j=0; j<=m+1; j++){ t[i][j]=tempt[i][j]; } } t[x][y]=!t[x][y]; for(int i=0; i<=n+1; i++){ for(int j=0; j<=m+1; j++){ tempt[i][j]=t[i][j]; } } tempvalue=0; value=-1; while(value!=0){ tempvalue+=value; value=0; vector<pair<int, int>> changes; for(int i=1; i<=n; i++){ for(int j=1; j<=m; j++){ if((!t[i-1][j]&&!t[i+1][j])||(!t[i][j-1]&&!t[i][j+1])){ changes.push_back({i, j}); value++; } } } for(auto idx : changes){ t[idx.first][idx.second]=0; } } cout<<tempvalue<<'\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 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | using namespace std; #include <bits/stdc++.h> int main() { int n,m,k,q; cin>>n>>m>>k>>q; bool t[n+2][m+2]; for(int i=0; i<=n+1; i++){ t[i][0]=0; } for(int i=0; i<=m+1; i++){ t[0][i]=0; } for(int i=0; i<k; i++){ int x,y; cin>>x>>y; t[x][y]=1; } bool tempt[n+2][m+2]; for(int i=0; i<=n+1; i++){ for(int j=0; j<=m+1; j++){ tempt[i][j]=t[i][j]; } } int tempvalue=0; int value=-1; while(value!=0){ tempvalue+=value; value=0; vector<pair<int, int>> changes; for(int i=1; i<=n; i++){ for(int j=1; j<=m; j++){ if((!t[i-1][j]&&!t[i+1][j])||(!t[i][j-1]&&!t[i][j+1])){ changes.push_back({i, j}); value++; } } } for(auto idx : changes){ t[idx.first][idx.second]=0; } } cout<<tempvalue<<'\n'; for(int o=0; o<q; o++){ int x,y; cin>>x>>y; for(int i=0; i<=n+1; i++){ for(int j=0; j<=m+1; j++){ t[i][j]=tempt[i][j]; } } t[x][y]=!t[x][y]; for(int i=0; i<=n+1; i++){ for(int j=0; j<=m+1; j++){ tempt[i][j]=t[i][j]; } } tempvalue=0; value=-1; while(value!=0){ tempvalue+=value; value=0; vector<pair<int, int>> changes; for(int i=1; i<=n; i++){ for(int j=1; j<=m; j++){ if((!t[i-1][j]&&!t[i+1][j])||(!t[i][j-1]&&!t[i][j+1])){ changes.push_back({i, j}); value++; } } } for(auto idx : changes){ t[idx.first][idx.second]=0; } } cout<<tempvalue<<'\n'; } return 0; } |