#include<bits/stdc++.h> #define endl "\n" using namespace std; const int N = ((int)(2e2))+50; struct point{ int x; int y; }; int n,m,q; point p1, p2, p3; bool tab[N][N]; int cols[N]; int rows[N]; int getAnswer(){ //~ int ans = 0; for (int x = 1; x <= n; x++){ cols[x] = 0; rows[x] = 0; } int cnt = 0, ones = 0; for (int x = 1; x <= n; x++){ for (int y = 1; y <= n; y++){ if(tab[x][y] == 0){ cols[x]++; rows[y]++; } } } for (int x = 1; x <= n; x++){ for (int y = 1; y <= n; y++){ if(tab[x][y] == 1){ ones++; if((cols[x] == 0) && (cols[y]==0)){ cnt++; } } } } int tmp = ones-cnt; return min(tmp, (n*n)-ones); } int main(){ ios_base::sync_with_stdio( 0 ); cin.tie( 0 ); cout.tie( 0 ); cin>>n>>m>>q; for (int i = 0; i < m; i++){ cin>>p1.x>>p2.x>>p1.y>>p2.y; for (int x = p1.x; x <= p1.y; x++){ for (int y = p2.x; y <= p2.y; y++){ tab[x][y] ^= 1; } } } cout<<getAnswer()<<endl; for (int i = 0; i < q; i++){ cin>>p3.x>>p3.y; tab[p3.x][p3.y] ^= 1; cout<<getAnswer()<<endl; } 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 | #include<bits/stdc++.h> #define endl "\n" using namespace std; const int N = ((int)(2e2))+50; struct point{ int x; int y; }; int n,m,q; point p1, p2, p3; bool tab[N][N]; int cols[N]; int rows[N]; int getAnswer(){ //~ int ans = 0; for (int x = 1; x <= n; x++){ cols[x] = 0; rows[x] = 0; } int cnt = 0, ones = 0; for (int x = 1; x <= n; x++){ for (int y = 1; y <= n; y++){ if(tab[x][y] == 0){ cols[x]++; rows[y]++; } } } for (int x = 1; x <= n; x++){ for (int y = 1; y <= n; y++){ if(tab[x][y] == 1){ ones++; if((cols[x] == 0) && (cols[y]==0)){ cnt++; } } } } int tmp = ones-cnt; return min(tmp, (n*n)-ones); } int main(){ ios_base::sync_with_stdio( 0 ); cin.tie( 0 ); cout.tie( 0 ); cin>>n>>m>>q; for (int i = 0; i < m; i++){ cin>>p1.x>>p2.x>>p1.y>>p2.y; for (int x = p1.x; x <= p1.y; x++){ for (int y = p2.x; y <= p2.y; y++){ tab[x][y] ^= 1; } } } cout<<getAnswer()<<endl; for (int i = 0; i < q; i++){ cin>>p3.x>>p3.y; tab[p3.x][p3.y] ^= 1; cout<<getAnswer()<<endl; } return 0; } |