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

using namespace std;

#define f first
#define s second

const int MAXN = 213;

int ind[MAXN][MAXN];
vector<int> v[MAXN * MAXN];
int pref[MAXN][MAXN];
bool zap[MAXN * MAXN];
int pol[MAXN * MAXN];
int odw[MAXN * MAXN];
bool now[MAXN * MAXN];
bool ever[MAXN * MAXN];
int trn = 0;

void buduj(int n) {
    memset(pol, 0, sizeof(pol));
    memset(now, 0, sizeof(now));
    memset(ever, 0, sizeof(ever));
    for (int i = 1; i <= n * n; i++)
        v[i].clear();
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            if (pref[i][j] == 0) {
                zap[ind[i][j]] = false;
                continue;
            }
            zap[ind[i][j]] = true;
            for (int l = 1; l <= n; l++) {
                if (pref[i][l] == 0)
                    v[ind[i][j]].push_back(ind[i][l]);
                if (pref[l][j] == 0)
                    v[ind[i][j]].push_back(ind[l][j]);
            }
        }
    }
}

bool probuj(int x) {
    odw[x] = trn;
    now[x] = true;
    for (auto it:v[x]) {
        if (pol[it] == 0) {
            pol[it] = x;
            pol[x] = it;
            now[x] = false;
            return true;
        }
        if (!ever[pol[it]] && !now[pol[it]]) {
            bool b = probuj(pol[it]);
            if (b) {
                pol[it] = x;
                pol[x] = it;
                now[x] = false;
                return true;
            }
        }
    }
    ever[x] = true;
    now[x] = false;
    return false;
}

void matchuj(int n) {
    for (int i = 1; i <= n * n; i++) {
        if (zap[i]) {
            for (auto it:v[i]) {
                if (pol[it] == 0) {
                    pol[i] = it;
                    pol[it] = i;
                    break;
                }
            }
        }
    }

    for (int i = 1; i <= n * n; i++) {
        if (zap[i] && pol[i] == 0) {
            trn++;
            memset(ever, 0, sizeof(ever));
            probuj(i);
        }
    }
    int ans = 0;
    for (int i = 1; i <= n * n; i++) {
        if (pol[i] != 0)
            ans++;
    }
    cout << ans / 2 << '\n';
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, m, z;
    int x1, y1, x2, y2;
    cin >> n >> m >> z;
    while (m--) {
        cin >> x1 >> y1 >> x2 >> y2;
        pref[x1][y1]++;
        pref[x1][y2 + 1]--;
        pref[x2 + 1][y1]--;
        pref[x2 + 1][y2 + 1]++;
    }
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            ind[i][j] = (i - 1) * n + j;
            pref[i][j] += pref[i - 1][j] + pref[i][j - 1] - pref[i - 1][j - 1];
        }
    }
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++)
            pref[i][j] %= 2;
    }
    buduj(n);
    matchuj(n);
    while (z--) {
        cin >> x1 >> y1;
        pref[x1][y1]++;
        pref[x1][y1] %= 2;
        buduj(n);
        matchuj(n);
    }
    return 0;
}