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
#include <iostream>
#include <algorithm>
#include <vector>
#include <bitset>

using namespace std;
typedef long long int lli;
lli n;

lli count(vector<vector<bool>>& grid) {
    vector<int> r(n+1);
    vector<int> c(n+1);
    lli totalRings = 0;
    for (int row = 1; row <= n; row++) {
        for (int col = 1; col <= n; col++) {
            r[row] += grid[row][col];
            c[col] += grid[row][col];
            totalRings += grid[row][col];
        }
    }
    lli blockedRows = 0, zeroRows = 0;
    for (int i = 1; i < r.size(); i++) {
        if (r[i] == n) {
            blockedRows++;
        } else if (r[i] == 0) {
            zeroRows++;
        }
    }
    lli blockedCols = 0, zeroCols = 0;
    for (int i = 1; i < c.size(); i++) {
        if (c[i] == n) {
            blockedCols++;
        } else if (c[i] == 0) {
            zeroCols++;
        }
    }
//    lli unfillable = 0;
//    if (zeroRows > 0) {
//        for (int i = 1; i < c.size(); i++) {
//            unfillable += max(0ll, zeroRows - c[i]);
//        }
//    }
//    if (zeroCols > 0) {
//        for (int i = 1; i < r.size(); i++) {
//            unfillable += max(0ll, zeroCols - r[i]);
//        }
//    }
//    cout << "ones: " << totalRings << ", blocked rows: " << blockedRows << ", blocked cols: " << blockedCols;
//    cout << ", zero rows: " << zeroRows << ", zero cols: " << zeroCols << ", unfillable: " << unfillable << '\n';
    return min(totalRings - (blockedRows*blockedCols), n*n - totalRings - (zeroRows*zeroCols));
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    lli m, q;
    cin >> n >> m >> q;
//    cout << "n is " << n << '\n';
    vector<vector<bool>> grid(n+1, vector<bool>(n+1));
    while (m--) {
        lli x1, y1, x2, y2;
        cin >> x1 >> y1 >> x2 >> y2;
        for (int row = x1; row <= x2; row++) {
            for (int col = y1; col <= y2; col++) {
                grid[row][col] = !grid[row][col];
            }
        }
    }
//    cout << "start grid" << '\n';
//    for (int i = 1; i <= n; i++) {
//        for (int j = 1; j <= n; j++) {
//            cout << grid[i][j] << " ";
//        }
//        cout << '\n';
//    }
//    cout << "end grid" << '\n';
    vector<lli> res(q+1);
    res[0] = count(grid);
    for (int i = 1; i <= q; i++) {
        lli a, b;
        cin >> a >> b;
        grid[a][b] = !grid[a][b];
        res[i] = count(grid);
    }
    for (int i = 0; i <= q; i++) {
        cout << res[i] << '\n';
    }
    return 0;
}