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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
const int INF = 0x3f3f3f3f;

#define FOR(i,b,e) for(int i = (b); i < (e); i++)
#define TRAV(x,a) for(auto &x: (a))
#define SZ(x) ((int)x.size())
#define PB push_back
#define X first
#define Y second

const int N = 205;

bitset<N> vis_kol, vis_wiersz;
bitset<N> wolne_wiersz[2][N];
bitset<N> wolne_kol[2][N];
bitset<N> zajete_wiersz[2][N];
bitset<N> zajete_kol[2][N];

int n;
bool akt[N][N];
int match[N*N];
int id[N][N];
ii par[N*N];

int getId(int a, int b){
    return a*N+b;
}

void flip(int v){
    int x = par[v].X, y = par[v].Y;
    int wart = akt[x][y];
    akt[x][y] ^= 1;
    wolne_wiersz[wart][x][y] = 0;
    zajete_wiersz[wart][x][y] = 0;
    wolne_kol[wart][y][x] = 0;
    zajete_kol[wart][y][x] = 0;
    wolne_wiersz[wart^1][x][y] = 1;
    wolne_kol[wart^1][y][x] = 1;
    if(match[v]){
        int u = match[v];
        x = par[u].X, y = par[u].Y;
        wart = akt[x][y];
        wolne_wiersz[wart][x][y] = 1;
        zajete_wiersz[wart][x][y] = 0;
        wolne_kol[wart][y][x] = 1;
        zajete_kol[wart][y][x] = 0;
        match[v] = match[u] = 0;
    }
}

void klik(int wart, int x, int y){
    wolne_wiersz[wart][x][y] = 0;
    zajete_wiersz[wart][x][y] = 1;
    wolne_kol[wart][y][x] = 0;
    zajete_kol[wart][y][x] = 1;
}

bool dfs(int v){
    int x = par[v].X, y = par[v].Y;
    bool wierp = !vis_wiersz[x];
    bool kolp = !vis_kol[y];
    vis_wiersz[x] = vis_kol[y] = 1;
    bool wart = akt[x][y];
    if(wierp){
        // FOR(ind, 0, n) if(wolne_wiersz[wart^1][x][ind])
        int ind = wolne_wiersz[wart^1][x]._Find_first();
        if(ind != N){
            klik(wart, x, y);
            klik(wart^1, x, ind);
            match[v] = N*x + ind;
            match[N*x + ind] = v;
            return 1;
        }
    }
    if(kolp){
        // FOR(ind, 0, n) if(wolne_kol[wart^1][y][ind])
        int ind = wolne_kol[wart^1][y]._Find_first();
        if(ind != N){
            klik(wart, x, y);
            klik(wart^1, ind, y);
            match[v] = N*ind + y;
            match[N*ind + y] = v;
            return 1;
        }
    }
    if(wierp){
        // FOR(i, 0, N){
        //     if(zajete_wiersz[wart^1][x][i] == 0) continue;
        for(int i = zajete_wiersz[wart^1][x]._Find_first(); i < N; i = zajete_wiersz[wart^1][x]._Find_next(i)){
            int u = N*x + i, z = match[u];
            if((!vis_wiersz[par[z].X] || !vis_kol[par[z].Y]) && dfs(z)){
                match[v] = u;
                match[u] = v;
                klik(wart, x, y);
                return 1;
            }
        }
    }
    if(kolp){
        // FOR(i, 0, N){
        //     if(zajete_kol[wart^1][y][i] == 0) continue;
        for(int i = zajete_kol[wart^1][y]._Find_first(); i < N; i = zajete_kol[wart^1][y]._Find_next(i)){
            int u = N*i + y, z = match[u];
            if((!vis_wiersz[par[z].X] || !vis_kol[par[z].Y]) && dfs(z)){
                match[v] = u;
                match[u] = v;
                klik(wart, x, y);
                return 1;
            }
        }
    }
    return 0;
}

bool matchuj(int v){
    if(match[v]) return 0;
    vis_kol.reset();
    vis_wiersz.reset();
    return dfs(v);
}

void readInt(int &x){
    x = 0;
    char c = getchar();
    bool negative = 0;
    while(c < 33) c = getchar();
    if(c == '-') negative = 1, c = getchar();
    while('0' <= c && c <= '9') x = 10*x + c - '0', c = getchar();
    if(negative) x *= -1;
}

void solve(){
    int m, q;
    readInt(n), readInt(m), readInt(q);
    n++;
    FOR(i, 0, m){
        int a, b, c, d;
        readInt(a), readInt(b), readInt(c), readInt(d);
        akt[a][b] ^= 1;
        akt[a][d+1] ^= 1;
        akt[c+1][b] ^= 1;
        akt[c+1][d+1] ^= 1;
    }
    FOR(i, 1, n) FOR(j, 1, n) akt[i][j] ^= akt[i-1][j] ^ akt[i][j-1] ^ akt[i-1][j-1];
    FOR(i, 1, n) FOR(j, 1, n) id[i][j] = getId(i, j), par[getId(i, j)] = {i, j};
    FOR(i, 1, n) FOR(j, 1, n){
        wolne_wiersz[akt[i][j]][i][j] = 1;
        wolne_kol[akt[i][j]][j][i] = 1;
    }
    int lm = -1, mm = 0;
    while(lm < mm){
        lm = mm;
        FOR(i, 1, n) FOR(j, 1, n) if(akt[i][j] && matchuj(id[i][j])) mm++;
    }
    cout << mm << '\n';
    FOR(i, 0, q){
        int a, b;
        readInt(a), readInt(b);
        int v = id[a][b], u = match[v];
        flip(v);
        if(u) mm--;
        if(u && matchuj(u)) mm++;
        if(matchuj(v)) mm++;
        cout << mm << '\n';
    }
}

int main(){
    // ios::sync_with_stdio(0);
    // cin.tie(0);
    // int tt; cin >> tt;
    // FOR(te, 0, tt)
    solve();
    return 0;
}