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

void flip(std::set<int> &s, int e) {
    auto iterator = s.find(e);
    if (iterator == s.cend()) {
        s.insert(e);
    } else {
        s.erase(iterator);
    }
}

int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int n, m, q;
    std::cin >> n >> m >> q;
    std::vector<std::set<int>> cols, rows;
    cols.resize(n + 2);
    rows.resize(n + 2);
    for (int i = 0; i < m; ++i) {
        int x1, y1, x2, y2;
        std::cin >> x1 >> y1 >> x2 >> y2;
        for (int row = x1; row <= x2; ++row) {
            for (int y: {y1, y2 + 1}) {
                flip(rows[row], y);
            }
        }
        for (int col = y1; col <= y2; ++col) {
            for (int x: {x1, x2 + 1}) {
                flip(cols[col], x);
            }
        }
    }

    std::set<int> rowsFullOfOnes, rowsFullOfZeros;
    std::set<int> colsFullOfOnes, colsFullOfZeros;
    std::vector<int> onesPerColumn, onesPerRow;
    onesPerColumn.resize(n + 1);
    onesPerRow.resize(n + 1);
    for (int col = 1; col <= n; ++col) {
        int cur = 1;
        bool ones = false;
        for (auto row: cols[col]) {
            if (ones) {
                onesPerColumn[col] += row - cur;
            }
            ones = not ones;
            cur = row;
        }
        if (onesPerColumn[col] == n) colsFullOfOnes.insert(col);
        if (onesPerColumn[col] == 0) colsFullOfZeros.insert(col);
    }

    long long numberOfOnes = 0;
    for (int row = 1; row <= n; ++row) {
        int cur = 1;
        bool ones = false;
        for (auto col: rows[row]) {
            if (ones) {
                onesPerRow[row] += col - cur;
            }
            ones = not ones;
            cur = col;
        }
        if (onesPerRow[row] == n) rowsFullOfOnes.insert(row);
        if (onesPerRow[row] == 0) rowsFullOfZeros.insert(row);
        numberOfOnes += onesPerRow[row];
    }

    for (int round = 0; round <= q; ++round) {
        long long count = 0;
        long long excluded = 0;
        bool areOnesExcluded;
        if (not rowsFullOfOnes.empty()) {
            excluded = (long long)rowsFullOfOnes.size() * (long long)colsFullOfOnes.size();
            areOnesExcluded = true;
        } else {
            excluded = (long long)rowsFullOfZeros.size() * (long long)colsFullOfZeros.size();
            areOnesExcluded = false;
        }
        if (areOnesExcluded) {
            count = std::min(numberOfOnes - excluded, n * n - numberOfOnes);
        } else {
            count = std::min(numberOfOnes, n * n - numberOfOnes - excluded);
        }
        std::cout << count << std::endl;

        if (round == q) {
            break;
        }

        int x, y;
        std::cin >> x >> y;
        int previousNumberOfOnesInRow = onesPerRow[x];
        for (int col: {y, y + 1}) {
            flip(rows[x], col);
        }
        for (int row: {x, x + 1}) {
            flip(cols[y], row);
        }
        {
            int cur = 1;
            bool ones = false;
            onesPerColumn[y] = 0;
            for (auto row: cols[y]) {
                if (ones) {
                    onesPerColumn[y] += row - cur;
                }
                ones = not ones;
                cur = row;
            }
            if (onesPerColumn[y] == n) colsFullOfOnes.insert(y); else colsFullOfOnes.erase(y);
            if (onesPerColumn[y] == 0) colsFullOfZeros.insert(y); else colsFullOfZeros.erase(y);
        }
        {
            int cur = 1;
            bool ones = false;
            onesPerRow[x] = 0;
            for (auto col: rows[x]) {
                if (ones) {
                    onesPerRow[x] += col - cur;
                }
                ones = not ones;
                cur = col;
            }
            if (onesPerRow[x] == n) rowsFullOfOnes.insert(x); else rowsFullOfOnes.erase(x);
            if (onesPerRow[x] == 0) rowsFullOfZeros.insert(y); else rowsFullOfZeros.erase(x);
        }
        if (previousNumberOfOnesInRow < onesPerRow[x]) {
            ++numberOfOnes;
        } else {
            --numberOfOnes;
        }
    }
    return 0;
}