#include<iostream> #include<vector> using namespace std; long long circus[8002][8002]; long long columns[8002]; long long rows[8002]; long long col_max = 0; long long col_zero = 0; long long row_max = 0; long long row_zero = 0; long long ones = 0; long long zeros = 0; void change_range_circus(int x_1, int y_1, int x_2, int y_2){ circus[x_1][y_1] += 1; circus[x_2+1][y_1] += 1; circus[x_1][y_2+1] += 1; circus[x_2+1][y_2+1] += 1; } void form_circus(int n){ for(int i=1; i<=n; i++){ for(int j=1; j<=n; j++){ circus[i][j] += (circus[i][j-1] + circus[i-1][j] - circus[i-1][j-1]); circus[i][j] &= 1; } } } void sum_rows_columns(int n){ for(int i=1; i<=n; i++){ for(int j=1; j<=n; j++){ if(circus[i][j]==1){ columns[j]++; rows[i]++; ones++; }else{ zeros++; } } } } void check_max_zeros(int n){ for(int i=1; i<=n; i++){ if(columns[i]==n){ col_max++; } if(columns[i]==0){ col_zero++; } if(rows[i]==n){ row_max++; } if(rows[i]==0){ row_zero++; } } } void give_answer(){ long long blocked_zeros = row_zero*col_zero; long long blocked_ones = row_max*col_max; cout << min(zeros-blocked_zeros, ones-blocked_ones) <<"\n"; } void change_point(int x_1,int y_1, int n){ if(circus[x_1][y_1]==1){ circus[x_1][y_1]=0; zeros++; ones--; if(rows[x_1]==n){ row_max--; } rows[x_1]--; if(rows[x_1]==0){ row_zero++; } if(columns[y_1]==n){ col_max--; } columns[y_1]--; if(columns[y_1]==0){ col_zero++; } }else{ circus[x_1][y_1]=1; zeros--; ones++; if(rows[x_1]==0){ row_zero--; } rows[x_1]++; if(rows[x_1]==n){ row_max++; } if(columns[y_1]==0){ col_zero--; } columns[y_1]++; if(columns[y_1]==n){ col_max++; } } } int main(){ int n, m, q; cin >> n >> m>> q; for(int i=0; i<m; i++){ int x_1, y_1, x_2, y_2; cin>> x_1 >> y_1 >> x_2 >> y_2; change_range_circus(x_1, y_1, x_2, y_2); } form_circus(n); sum_rows_columns(n); check_max_zeros(n); give_answer(); for(int i=0; i<q; i++){ int x_1, y_1; cin >> x_1 >> y_1; change_point(x_1, y_1, n); give_answer(); } }
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 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 | #include<iostream> #include<vector> using namespace std; long long circus[8002][8002]; long long columns[8002]; long long rows[8002]; long long col_max = 0; long long col_zero = 0; long long row_max = 0; long long row_zero = 0; long long ones = 0; long long zeros = 0; void change_range_circus(int x_1, int y_1, int x_2, int y_2){ circus[x_1][y_1] += 1; circus[x_2+1][y_1] += 1; circus[x_1][y_2+1] += 1; circus[x_2+1][y_2+1] += 1; } void form_circus(int n){ for(int i=1; i<=n; i++){ for(int j=1; j<=n; j++){ circus[i][j] += (circus[i][j-1] + circus[i-1][j] - circus[i-1][j-1]); circus[i][j] &= 1; } } } void sum_rows_columns(int n){ for(int i=1; i<=n; i++){ for(int j=1; j<=n; j++){ if(circus[i][j]==1){ columns[j]++; rows[i]++; ones++; }else{ zeros++; } } } } void check_max_zeros(int n){ for(int i=1; i<=n; i++){ if(columns[i]==n){ col_max++; } if(columns[i]==0){ col_zero++; } if(rows[i]==n){ row_max++; } if(rows[i]==0){ row_zero++; } } } void give_answer(){ long long blocked_zeros = row_zero*col_zero; long long blocked_ones = row_max*col_max; cout << min(zeros-blocked_zeros, ones-blocked_ones) <<"\n"; } void change_point(int x_1,int y_1, int n){ if(circus[x_1][y_1]==1){ circus[x_1][y_1]=0; zeros++; ones--; if(rows[x_1]==n){ row_max--; } rows[x_1]--; if(rows[x_1]==0){ row_zero++; } if(columns[y_1]==n){ col_max--; } columns[y_1]--; if(columns[y_1]==0){ col_zero++; } }else{ circus[x_1][y_1]=1; zeros--; ones++; if(rows[x_1]==0){ row_zero--; } rows[x_1]++; if(rows[x_1]==n){ row_max++; } if(columns[y_1]==0){ col_zero--; } columns[y_1]++; if(columns[y_1]==n){ col_max++; } } } int main(){ int n, m, q; cin >> n >> m>> q; for(int i=0; i<m; i++){ int x_1, y_1, x_2, y_2; cin>> x_1 >> y_1 >> x_2 >> y_2; change_range_circus(x_1, y_1, x_2, y_2); } form_circus(n); sum_rows_columns(n); check_max_zeros(n); give_answer(); for(int i=0; i<q; i++){ int x_1, y_1; cin >> x_1 >> y_1; change_point(x_1, y_1, n); give_answer(); } } |