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
#include <bits/stdc++.h>
using namespace std;

#define REP(i, n) for (int i = 0; i < (int)n; i++)
#define ST first
#define ND second
#define MP make_pair
#define PB push_back

typedef vector<int> VI;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef set<int> SI;
typedef long long LL;

#ifdef DEBUG
const bool debug = true;
#else
const bool debug = false;
#endif

// #define MULTI_TASK true

const int INF = 1000 * 1000 * 1000;
const LL INFLL = 1e18;
const int MAKSN = 2000 + 13;
const LL MOD = (LL)(1e9 + 7);
LL N, M, k, l, a, b, c, d, maks = 0, q;
vector<LL> v;

vector<vector<bool>> col;
vector<pair<int, int>> E[MAKSN][MAKSN];
// vector<pair<int, int>> on_fire;

void zeruj() {
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            E[i][j].clear();
        }
    }
}
int events[MAKSN][MAKSN];

void readIn() {
    cin >> N >> M >> q;
    REP(i, N) {
        col.push_back(vector<bool>(N, false));
    }

    REP(it, M) {
        cin >> a >> b >> c >> d;
        a--;
        b--;
        c--;
        d--;
        for (int i = a; i <= c; i++) {
            events[i][b] += 1;
            events[i][d + 1] -= 1;
        }
    }

    for (int i = 0; i < N; i++) {
        int c = 0;
        for (int j = 0; j < N; j++) {
            c += events[i][j];

            if (c % 2 == 1) {
                col[i][j] = 1;
            } else {
                col[i][j] = 0;
            }
        }
    }
}

int odw[MAKSN][MAKSN];
pair<int, int> partner[MAKSN][MAKSN];
int nr = 1;

void buildGraph() {
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            for (int k = 0; k < N; k++) {
                if (k != j && col[i][j] ^ col[i][k]) {
                    E[i][j].push_back({i, k});
                }
                if (k != i && col[i][j] ^ col[k][j]) {
                    E[i][j].push_back({k, j});
                }
            }
        }
    }

    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            partner[i][j] = {-1, -1};
            odw[i][j] = 0;
        }
    }
}

bool match(int x, int y) {
    odw[x][y] = nr;
    for (pair<int, int> neigh : E[x][y]) {
        if (partner[neigh.ST][neigh.ND] == make_pair(-1, -1)) {
            partner[neigh.ST][neigh.ND] = {x, y};
            return true;
        }
    }
    for (pair<int, int> neigh : E[x][y]) {
        PII p = partner[neigh.ST][neigh.ND];

        if (odw[p.ST][p.ND] != nr && match(p.ST, p.ND)) {
            partner[neigh.ST][neigh.ND] = {x, y};
            return true;
        }
    }
    return false;
}

void answerOne() {
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            nr++;
            if (col[i][j])
                match(i, j);
        }
    }
    int res = 0;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            if (!col[i][j] && partner[i][j] != make_pair(-1, -1)) {
                res++;
            }
        }
    }
    cout << res << "\n";
}

void solve() {
    buildGraph();
    answerOne();
    for (int qNr = 0; qNr < q; qNr++) {
        cin >> a >> b;
        a--;
        b--;
        col[a][b] = col[a][b] ^ 1;
        zeruj();
        buildGraph();
        answerOne();
    }
}

int main() {
    ios_base::sync_with_stdio(0);
#ifdef MULTI_TASK
    int test;
    cin >> test;
    while (test--) {
#endif
        zeruj();
        readIn();
        solve();
#ifdef MULTI_TASK
    }
#endif
    return 0;
}