#include <bits/stdc++.h> using namespace std; int table[2005][2005]; int horizontal[2005]; int vertical[2005]; int horizontal_full,horizontal_empty,vertical_full,vertical_empty,sum; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); int n,m,q; cin >> n >> m >> q; horizontal_empty=n; vertical_empty=n; for(int i=0;i<m;i++){ int x1,x2,y1,y2; cin >> x1 >> y1 >> x2 >> y2; for(int j=x1;j<=x2;j++){ for(int k=y1;k<=y2;k++){ if(table[j][k]==0){ if(horizontal[j]==0)horizontal_empty--; if(vertical[k]==0)vertical_empty--; //if(horizontal[j]==0 && vertical[k]==0)full_without--; table[j][k]=1; horizontal[j]++; vertical[k]++; if(horizontal[j]==n)horizontal_full++; if(vertical[k]==n)vertical_full++; //if(horizontal[j]==n && vertical[k]==n)full_with++; sum++; } else{ if(horizontal[j]==n)horizontal_full--; if(vertical[k]==n)vertical_full--; //if(horizontal[j]==n && vertical[k]==n)full_with--; table[j][k]=0; horizontal[j]--; vertical[k]--; if(horizontal[j]==0)horizontal_empty++; if(vertical[k]==0)vertical_empty++; //if(horizontal[j]==0 && vertical[k]==0)full_without++; sum--; } } } } /*for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++){ cout << table[i][j] << " "; } cout << endl; }*/ //cout << "jjjj " << sum << " " << horizontal_full << " " << vertical_full << endl; //cout << "jjjj " << horizontal_empty << " " << vertical_empty << endl; cout << min(sum-horizontal_full*vertical_full,n*n-sum-horizontal_empty*vertical_empty) << "\n"; for(int i=0;i<q;i++){ int x,y; cin >> x >> y; if(table[x][y]==0){ if(horizontal[x]==0)horizontal_empty--; if(vertical[y]==0)vertical_empty--; //if(horizontal[x]==0 && vertical[y]==0)full_without--; table[x][y]=1; horizontal[x]++; vertical[y]++; if(horizontal[x]==n)horizontal_full++; if(vertical[y]==n)vertical_full++; //if(horizontal[x]==n && vertical[y]==n)full_with++; sum++; } else{ if(horizontal[x]==n)horizontal_full--; if(vertical[y]==n)vertical_full--; //if(horizontal[x]==n && vertical[y]==n)full_with--; table[x][y]=0; horizontal[x]--; vertical[y]--; if(horizontal[x]==0)horizontal_empty++; if(vertical[y]==0)vertical_empty++; //if(horizontal[x]==0 && vertical[y]==0)full_without++; sum--; } //cout << "jjjj " << sum << " " << horizontal_full << " " << vertical_full << endl; //cout << "jjjj " << horizontal_empty << " " << vertical_empty << endl; cout << min(sum-horizontal_full*vertical_full,n*n-sum-horizontal_empty*vertical_empty) << "\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 88 89 90 91 | #include <bits/stdc++.h> using namespace std; int table[2005][2005]; int horizontal[2005]; int vertical[2005]; int horizontal_full,horizontal_empty,vertical_full,vertical_empty,sum; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); int n,m,q; cin >> n >> m >> q; horizontal_empty=n; vertical_empty=n; for(int i=0;i<m;i++){ int x1,x2,y1,y2; cin >> x1 >> y1 >> x2 >> y2; for(int j=x1;j<=x2;j++){ for(int k=y1;k<=y2;k++){ if(table[j][k]==0){ if(horizontal[j]==0)horizontal_empty--; if(vertical[k]==0)vertical_empty--; //if(horizontal[j]==0 && vertical[k]==0)full_without--; table[j][k]=1; horizontal[j]++; vertical[k]++; if(horizontal[j]==n)horizontal_full++; if(vertical[k]==n)vertical_full++; //if(horizontal[j]==n && vertical[k]==n)full_with++; sum++; } else{ if(horizontal[j]==n)horizontal_full--; if(vertical[k]==n)vertical_full--; //if(horizontal[j]==n && vertical[k]==n)full_with--; table[j][k]=0; horizontal[j]--; vertical[k]--; if(horizontal[j]==0)horizontal_empty++; if(vertical[k]==0)vertical_empty++; //if(horizontal[j]==0 && vertical[k]==0)full_without++; sum--; } } } } /*for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++){ cout << table[i][j] << " "; } cout << endl; }*/ //cout << "jjjj " << sum << " " << horizontal_full << " " << vertical_full << endl; //cout << "jjjj " << horizontal_empty << " " << vertical_empty << endl; cout << min(sum-horizontal_full*vertical_full,n*n-sum-horizontal_empty*vertical_empty) << "\n"; for(int i=0;i<q;i++){ int x,y; cin >> x >> y; if(table[x][y]==0){ if(horizontal[x]==0)horizontal_empty--; if(vertical[y]==0)vertical_empty--; //if(horizontal[x]==0 && vertical[y]==0)full_without--; table[x][y]=1; horizontal[x]++; vertical[y]++; if(horizontal[x]==n)horizontal_full++; if(vertical[y]==n)vertical_full++; //if(horizontal[x]==n && vertical[y]==n)full_with++; sum++; } else{ if(horizontal[x]==n)horizontal_full--; if(vertical[y]==n)vertical_full--; //if(horizontal[x]==n && vertical[y]==n)full_with--; table[x][y]=0; horizontal[x]--; vertical[y]--; if(horizontal[x]==0)horizontal_empty++; if(vertical[y]==0)vertical_empty++; //if(horizontal[x]==0 && vertical[y]==0)full_without++; sum--; } //cout << "jjjj " << sum << " " << horizontal_full << " " << vertical_full << endl; //cout << "jjjj " << horizontal_empty << " " << vertical_empty << endl; cout << min(sum-horizontal_full*vertical_full,n*n-sum-horizontal_empty*vertical_empty) << "\n"; } return 0; } |