#include<cstdio> #include<algorithm> #include<vector> #include<utility> typedef std::pair<int, int> pii; typedef std::vector<pii> vpii; typedef std::vector<int> vi; int n, m, q; int ** d; bool cmp_p(pii & p1, pii & p2) { if (p1.first < p2.first) { return true; } else if (p1.first == p2.first) { return p1.second < p2.second; } else { return false; } } void print_d() { for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { printf("%d ", d[i][j]); } printf("\n"); } printf("\n"); } void input() { scanf("%d %d %d", &n, &m, &q); d = new int * [n]; for (int i = 0; i < n; i++) { d[i] = new int[n]; } vi t[n]; int x1, y1, x2, y2; for (int i = 0; i < m; i++) { scanf("%d %d %d %d", &x1, &y1, &x2, &y2); // for (int i = x1; i <= x2; i++) { // for (int j = y1; j <= y2; j++) { // d[i - 1][j - 1] = 1 - d[i - 1][j - 1]; // } // } for (int j = y1; j <= y2; j++) { t[j - 1].push_back(x1 - 1); t[j - 1].push_back(x2); } } // print_d(); for (int i = 0; i < n; i++) { std::sort(t[i].begin(), t[i].end()); int v = 0; int k = 0; for (int j = 0; j < n; j++) { while(k < t[i].size() && t[i][k] == j) { k++; v = 1 - v; } d[j][i] = v; } } // print_d(); } int count(int w) { int res = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (d[i][j] == 1) { for (int k = 0; k < n; k++) { if (d[i][k] != 1) { d[i][k] = w; res++; break; } if (d[k][j] != 1) { d[k][j] = w; res++; break; } } } } } return res; } void solve() { printf("%d\n", count(2)); int x, y; for (int i = 0; i < q; i++) { scanf("%d %d", &x, &y); d[x - 1][y - 1] = 1 - d[x - 1][y - 1]; printf("%d\n", count(3 + i)); } } int main() { input(); solve(); 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 | #include<cstdio> #include<algorithm> #include<vector> #include<utility> typedef std::pair<int, int> pii; typedef std::vector<pii> vpii; typedef std::vector<int> vi; int n, m, q; int ** d; bool cmp_p(pii & p1, pii & p2) { if (p1.first < p2.first) { return true; } else if (p1.first == p2.first) { return p1.second < p2.second; } else { return false; } } void print_d() { for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { printf("%d ", d[i][j]); } printf("\n"); } printf("\n"); } void input() { scanf("%d %d %d", &n, &m, &q); d = new int * [n]; for (int i = 0; i < n; i++) { d[i] = new int[n]; } vi t[n]; int x1, y1, x2, y2; for (int i = 0; i < m; i++) { scanf("%d %d %d %d", &x1, &y1, &x2, &y2); // for (int i = x1; i <= x2; i++) { // for (int j = y1; j <= y2; j++) { // d[i - 1][j - 1] = 1 - d[i - 1][j - 1]; // } // } for (int j = y1; j <= y2; j++) { t[j - 1].push_back(x1 - 1); t[j - 1].push_back(x2); } } // print_d(); for (int i = 0; i < n; i++) { std::sort(t[i].begin(), t[i].end()); int v = 0; int k = 0; for (int j = 0; j < n; j++) { while(k < t[i].size() && t[i][k] == j) { k++; v = 1 - v; } d[j][i] = v; } } // print_d(); } int count(int w) { int res = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (d[i][j] == 1) { for (int k = 0; k < n; k++) { if (d[i][k] != 1) { d[i][k] = w; res++; break; } if (d[k][j] != 1) { d[k][j] = w; res++; break; } } } } } return res; } void solve() { printf("%d\n", count(2)); int x, y; for (int i = 0; i < q; i++) { scanf("%d %d", &x, &y); d[x - 1][y - 1] = 1 - d[x - 1][y - 1]; printf("%d\n", count(3 + i)); } } int main() { input(); solve(); return 0; } |