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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
// Karol Kosinski 2020
#include <cstdio>
#include <list>
#include <queue>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FORE(i,q) for(auto i=(q).begin();i!=(q).end();++i)
//#define DEBUG(x...) printf(x)
#define DEBUG(x...)
using namespace std;

typedef unsigned long long LL;
const int NX = 205;
const int LEN = 64;

LL Bits[LEN + 1][LEN + 1];
LL A[NX][ NX / LEN + 1];
int Code[NX][NX];

void preproc()
{
    FOR(i,0,LEN)
    {
        Bits[i][i] = (1LL << i);
        FOR(j,i+1,LEN)
        {
            Bits[i][j] = Bits[i][ j - 1 ] | (1LL << j);
        }
    }
}

void print_bits(int n, int nlen)
{
    FOR(i,0,n)
    {
        FOR(j,0,nlen) FOR(k,0,LEN)
        {
            DEBUG("%d", (A[i][j] & (1LL << k)) != 0);
        }
        DEBUG("\n");
    }
    DEBUG("\n");
}

////////////////////////////////////////////////////////

int n1, n2, res;
list<int> G[NX * NX];
queue<int> Q;
int D[NX * NX], M[NX * NX];
bool was[NX * NX];

bool bfs() {
    bool good = false;
    FOR(i,1,n1+1)
        if(M[i] != 0) D[i] = -1;
        else Q.push(i), D[i] = 0;
    FOR(i,n1+1,n2+1) D[i] = -1;
    int limit = 1234567890;
    while(!Q.empty()) {
        int u = Q.front(); Q.pop();
        if(limit < D[u]) break;
        FORE(i,G[u]) {
            if(*i <= n1 || D[*i] != -1) continue;
            D[*i] = D[u] + 1;
            if(M[*i] == 0) limit = D[*i], good = true;
            else if(D[M[*i]] == -1) {
                D[M[*i]] = D[u] + 2;
                Q.push(M[*i]);
            }
        }
    }
    while(!Q.empty()) Q.pop();
    return good;
}

bool dfs(int s) {
    was[s] = true;
    FORE(i,G[s]) {
        if(was[*i] || D[*i] != D[s] + 1) continue;
        was[*i] = true;
        if(M[*i] == 0 || (!was[M[*i]] && dfs(M[*i]))) {
            M[s] = *i, M[*i] = s;
            return true;
        }
    }
    return false;
}

void hopcroft_karp() {
    FOR(i,1,n2+1) M[i] = 0;
    while(bfs()) {
        FOR(i,1,n2+1) was[i] = false;
        FOR(i,1,n1+1) if(M[i] == 0) dfs(i);
    }
    FOR(i,1,n2+1) G[i].clear();
    while(!Q.empty()) Q.pop();
    FOR(i,1,n1+1)
    {
        if(D[i] == -1) ++res;
        DEBUG("%d(%d) ", i , D[i]);
    }
    FOR(i,n1+1,n2+1)
    {
        if(D[i] > -1) ++res;
        DEBUG("%d(%d) ", i , D[i]);
    }
    DEBUG("\n");
}

////////////////////////////////////////////////////////

void print_graph(int n)
{
    FOR(i,1,n*n+1)
    {
        DEBUG("** (%d)\n", i);
        for (int v : G[i]) DEBUG("%d ", v);
        DEBUG("\n");
    }
    DEBUG("\n");
}

void prepare_graph(int n, int nlen)
{
    int down = 0, up = n * n + 1;
    FOR(i,0,n)
    {
        FOR(j,0,nlen)
        {
            int lim = (j == nlen - 1) ? n % LEN : LEN;
            FOR(k,0,lim)
            {
                if ((A[i][j] & (1LL << k)) != 0)
                {
                    Code[i][ j * LEN + k ] = ++down;
                    DEBUG("%4d", down);
                }
                else
                {
                    Code[i][ j * LEN + k ] = --up;
                    DEBUG("%4d", up);
                }
            }
        }
        DEBUG("\n");
    }
    n1 = down, n2 = n * n;
    FOR(i,0,n) FOR(j,0,n)
    {
        if (Code[i][j] > n1) continue;
        int b = Code[i][j];
        auto& g = G[b];
        FOR(k,0,n)
        {
            int c = Code[k][j];
            if (k != i && c > n1)
            {
                g.push_back(c);
                G[c].push_back(b);
            }
            int d = Code[i][k];
            if (k != j && d > n1)
            {
                g.push_back(d);
                G[d].push_back(b);
            }
        }
    }
    DEBUG("-- %d %d\n\n", n1, n2);
}

int main()
{
    int n, m, q;
    scanf("%d%d%d", &n, &m, &q);
    preproc();
    int nlen = n / LEN + int(n % LEN != 0);
    FOR(_,0,m)
    {
        int x1, y1, x2, y2;
        scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
        --x1, --y1, --y2;
        int yd1 = y1 / LEN, yd2 = y2 / LEN;
        int ym1 = y1 % LEN, ym2 = y2 % LEN;
        if (yd1 == yd2)
        {
            FOR(i,x1,x2) A[i][yd1] ^= Bits[ym1][ym2];
            DEBUG("[%d, %d]  %llx\n", ym1, ym2, Bits[ym1][ym2]);
        }
        else
        {
            FOR(i,x1,x2)
            {
                A[i][yd1] ^= Bits[ym1][ LEN - 1 ];
                FOR(j, yd1 + 1, yd2) A[i][j] ^= Bits[0][ LEN - 1 ];
                A[i][yd2] ^= Bits[0][ym2];
            }
        }
        //print_bits(n, nlen);       // DEBUG
    }

    //print_graph(n);                 // DEBUG
    prepare_graph(n, nlen);
    hopcroft_karp();
    printf("%d\n", res);
    FOR(_,0,q)
    {
        int a, b;
        scanf("%d%d", &a, &b);
        --a, --b;
        A[a][b / LEN] ^= (1LL << (b % LEN));
        res = 0;
        prepare_graph(n, nlen);
        hopcroft_karp();
        printf("%d\n", res);
    }
    return 0;
}