#include <bits/stdc++.h>
using namespace std;
void test_case() {
int64_t n, m, q;
cin >> n >> m >> q;
vector<vector<int>> a(n+1, vector<int>(n+1));
vector<vector<int>> dp(n+2, vector<int>(n+2));
for (int i = 0; i < m; i++) {
int x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2;
dp[x1][y1] += 1;
dp[x2 + 1][y2 + 1] += 1;
dp[x1][y2 + 1] -= 1;
dp[x2 + 1][y1] -= 1;
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
dp[i][j] = dp[i][j] + dp[i - 1][j] + dp[i][j - 1]
- dp[i - 1][j - 1];
if (dp[i][j] % 2 != 0) {
a[i][j] = a[i][j] ^ 1;
}
}
}
vector<int> row(n + 1);
vector<int> col(n + 1);
vector<int64_t> ans;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
row[i] += a[i][j];
}
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
col[i] += a[j][i];
}
}
int full_rows = 0;
int full_cols = 0;
for (int i = 1; i <= n; i++) {
full_rows += (row[i] == n);
}
for (int i = 1; i <= n; i++) {
full_cols += (col[i] == n);
}
int64_t with_hula = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
with_hula += a[i][j];
}
}
int64_t zeroth = min(with_hula - full_cols * full_rows, n * n - with_hula);
ans.push_back(zeroth);
for (int i = 0; i < q; i++) {
int x, y;
cin >> x >> y;
if (a[x][y] == 1) {
with_hula--;
row[x]--;
col[y]--;
if (row[x] == n - 1)
full_rows--;
if (col[y] == n - 1)
full_cols--;
} else {
with_hula++;
row[x]++;
col[y]++;
if (row[x] == n)
full_rows++;
if (col[y] == n)
full_cols++;
}
zeroth = min(with_hula - full_cols * full_rows, n * n - with_hula);
ans.push_back(zeroth);
}
for (auto el : ans) {
cout << el << '\n';
}
}
void solve() {
test_case();
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
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 | #include <bits/stdc++.h> using namespace std; void test_case() { int64_t n, m, q; cin >> n >> m >> q; vector<vector<int>> a(n+1, vector<int>(n+1)); vector<vector<int>> dp(n+2, vector<int>(n+2)); for (int i = 0; i < m; i++) { int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2; dp[x1][y1] += 1; dp[x2 + 1][y2 + 1] += 1; dp[x1][y2 + 1] -= 1; dp[x2 + 1][y1] -= 1; } for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { dp[i][j] = dp[i][j] + dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1]; if (dp[i][j] % 2 != 0) { a[i][j] = a[i][j] ^ 1; } } } vector<int> row(n + 1); vector<int> col(n + 1); vector<int64_t> ans; for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { row[i] += a[i][j]; } } for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { col[i] += a[j][i]; } } int full_rows = 0; int full_cols = 0; for (int i = 1; i <= n; i++) { full_rows += (row[i] == n); } for (int i = 1; i <= n; i++) { full_cols += (col[i] == n); } int64_t with_hula = 0; for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { with_hula += a[i][j]; } } int64_t zeroth = min(with_hula - full_cols * full_rows, n * n - with_hula); ans.push_back(zeroth); for (int i = 0; i < q; i++) { int x, y; cin >> x >> y; if (a[x][y] == 1) { with_hula--; row[x]--; col[y]--; if (row[x] == n - 1) full_rows--; if (col[y] == n - 1) full_cols--; } else { with_hula++; row[x]++; col[y]++; if (row[x] == n) full_rows++; if (col[y] == n) full_cols++; } zeroth = min(with_hula - full_cols * full_rows, n * n - with_hula); ans.push_back(zeroth); } for (auto el : ans) { cout << el << '\n'; } } void solve() { test_case(); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); solve(); return 0; } |
English