#include <algorithm> #include <cstdio> #include <vector> #include <set> using namespace std; long a[2002][2002]; int main() { long n, m, q; scanf("%ld%ld%ld", &n, &m, &q); long x1, x2, y1, y2; for (long i = 0; i < m; i++) { scanf("%ld%ld%ld%ld", &x1, &y1, &x2, &y2); for (long x = x1; x <= x2; x++) for (long y = y1; y <= y2; y++) a[x][y] = 1 - a[x][y]; } long s1 = 0; for (long x = 1; x <= n; x++) for (long y = 1; y <= n; y++) { a[x][0] += a[x][y]; a[0][y] += a[x][y]; s1 += a[x][y]; } long b0 = 0, b1 = 0; for (long x = 1; x <= n; x++) for (long y = 1; y <= n; y++) { if (a[x][0] == n && a[0][y] == n) { a[x][n + 1]++; a[n + 1][y]++; b1++; } if (a[x][0] == 0 && a[0][y] == 0) { a[x][n + 1]++; a[n + 1][y]++; b0++; } } printf("%ld\n", min(n*n - s1 - b0, s1 - b1)); //for (long x = 1; x <= n; x++) //{ // for (long y = 1; y <= n; y++) // printf("%ld", a[x][y]); // printf("\n"); //} long x, y; for (long i = 0; i < q; i++) { scanf("%ld%ld", &x, &y); if (a[x][y] == 1) { if (a[x][0] == n) { for (long j = 1; j <= n; j++) { if (a[0][j] == n) b1--; } } a[x][0]--; if (a[0][y] == n) { for (long j = 1; j <= n; j++) { if (a[j][0] == n) b1--; } } a[0][y]--; s1--; if (a[x][0] == 0) { for (long j = 1; j <= n; j++) { if (a[0][j] == 0) b0++; } } if (a[0][y] == 0) { for (long j = 1; j <= n; j++) { if (a[j][0] == 0) b0++; } } if (a[x][0] == 0 && a[0][y] == 0) b0--; } else { if (a[x][0] == 0) { for (long j = 1; j <= n; j++) { if (a[0][j] == 0) b0--; } } a[x][0]++; if (a[0][y] == 0) { for (long j = 1; j <= n; j++) { if (a[j][0] == 0) b0--; } } a[0][y]++; s1++; if (a[x][0] == n) { for (long j = 1; j <= n; j++) { if (a[0][j] == n) b1++; } } if (a[0][y] == n) { for (long j = 1; j <= n; j++) { if (a[j][0] == n) b1++; } } if (a[x][0] == n && a[0][y] == n) b1--; } a[x][y] = 1 - a[x][y]; printf("%ld\n", min(n*n - s1 - b0, s1 - b1)); } 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 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 | #include <algorithm> #include <cstdio> #include <vector> #include <set> using namespace std; long a[2002][2002]; int main() { long n, m, q; scanf("%ld%ld%ld", &n, &m, &q); long x1, x2, y1, y2; for (long i = 0; i < m; i++) { scanf("%ld%ld%ld%ld", &x1, &y1, &x2, &y2); for (long x = x1; x <= x2; x++) for (long y = y1; y <= y2; y++) a[x][y] = 1 - a[x][y]; } long s1 = 0; for (long x = 1; x <= n; x++) for (long y = 1; y <= n; y++) { a[x][0] += a[x][y]; a[0][y] += a[x][y]; s1 += a[x][y]; } long b0 = 0, b1 = 0; for (long x = 1; x <= n; x++) for (long y = 1; y <= n; y++) { if (a[x][0] == n && a[0][y] == n) { a[x][n + 1]++; a[n + 1][y]++; b1++; } if (a[x][0] == 0 && a[0][y] == 0) { a[x][n + 1]++; a[n + 1][y]++; b0++; } } printf("%ld\n", min(n*n - s1 - b0, s1 - b1)); //for (long x = 1; x <= n; x++) //{ // for (long y = 1; y <= n; y++) // printf("%ld", a[x][y]); // printf("\n"); //} long x, y; for (long i = 0; i < q; i++) { scanf("%ld%ld", &x, &y); if (a[x][y] == 1) { if (a[x][0] == n) { for (long j = 1; j <= n; j++) { if (a[0][j] == n) b1--; } } a[x][0]--; if (a[0][y] == n) { for (long j = 1; j <= n; j++) { if (a[j][0] == n) b1--; } } a[0][y]--; s1--; if (a[x][0] == 0) { for (long j = 1; j <= n; j++) { if (a[0][j] == 0) b0++; } } if (a[0][y] == 0) { for (long j = 1; j <= n; j++) { if (a[j][0] == 0) b0++; } } if (a[x][0] == 0 && a[0][y] == 0) b0--; } else { if (a[x][0] == 0) { for (long j = 1; j <= n; j++) { if (a[0][j] == 0) b0--; } } a[x][0]++; if (a[0][y] == 0) { for (long j = 1; j <= n; j++) { if (a[j][0] == 0) b0--; } } a[0][y]++; s1++; if (a[x][0] == n) { for (long j = 1; j <= n; j++) { if (a[0][j] == n) b1++; } } if (a[0][y] == n) { for (long j = 1; j <= n; j++) { if (a[j][0] == n) b1++; } } if (a[x][0] == n && a[0][y] == n) b1--; } a[x][y] = 1 - a[x][y]; printf("%ld\n", min(n*n - s1 - b0, s1 - b1)); } return 0; } |