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
/*
 * author: pavveu
 * task: Potyczki Algorytmiczne 2020 Runda 5 - Krolewski Bal [B]
*/

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;

#define FOR(iter, val) for(int iter = 0; iter < (val); iter++)
#define all(x) begin(x), end(x)

template<typename T>
void initialize_matrix(vector<vector<T>>& matrix, int rows, int cols, T val) {
	assert(matrix.empty());
	FOR(row, rows) 
		matrix.emplace_back(cols, val);
}


struct hopcroft_karp_matcher {
	static const int INF = 2e9 + 10;
	static const int MAXV = 2010;

	int PV[MAXV], PU[MAXV], D[MAXV];
	vector<int> G[MAXV];

	int U,V;

	bool bfs() {
		queue<int> Q;

		for(int u = 1; u <= U; u++) {
			if(PU[u])	D[u] = INF;
			else {
				D[u] = 0;
				Q.push(u);
			}
		}	

		D[0] = INF;
		while(Q.size()) {
			int u = Q.front();	Q.pop();
			
			if(D[u] < D[0]) {
				for(int v : G[u])	{
					if(D[PV[v]] != INF) continue;
					
					D[PV[v]] = D[u]+1;	
					Q.push(PV[v]);
				}
			}
		}
		return (D[0] != INF);
	}

	bool dfs(int u) {
		if(!u) return true;

		for(int v : G[u]) {
			if(D[PV[v]] == D[u]+1 && dfs(PV[v]) == true) {
					PV[v] = u;
					PU[u] = v;
					return true;
			}
		}

		D[u] = INF;
		return false;
	}


	void init(vector<pair<int,int>>& edges) {

		

		set<int> u_vertices;
		set<int> v_vertices;


		for (auto p : edges) {
			auto[u, v] = p;
			u_vertices.insert(u);
			v_vertices.insert(v);
		}

		U = u_vertices.size();
		V = v_vertices.size();

		vector<int> id(U + V + 10, 0);

		FOR(i, U + V + 9) {
			PU[i] = 0;
			PV[i] = 0;
			G[i].clear();
		}


		int ids = 1;
		for (int x : u_vertices) {
			id[x] = ids++;
		}

		for (int x : v_vertices) {
			id[x] = ids++;
		}


		for (auto p : edges) {
			auto[u, v] = p;
			G[id[u]].push_back(id[v]);
			G[id[v]].push_back(id[u]);
		}
	}

	int get_matching() {
		int match = 0;
		while(bfs()) {
			for(int u = 1; u <= U; u++) {
				if(!PU[u] && dfs(u))	
						match++;
			}			
		}
		return match;
	}
};

vector<pair<int,int>> get_bipartite_edges(vector<vector<int>>& board) {
	int n = board.size();

	vector<pair<int,int>> edges;

	FOR(i, n) {
		FOR(j, n) {
			if ( board[i][j] == 1 ) 
				continue;

			int u { i * n + j + 1 };

			FOR(k, n) {
				if ( board[i][k] ) edges.emplace_back(u, i * n + k + 1);
				if ( board[k][j] ) edges.emplace_back(u, k * n + j + 1);
			}
		}
	}
	return edges;
}

void go() {
	int n, m, q;
	cin >> n >> m >> q;

	vector<vector<int>> summary;
	initialize_matrix(summary, n, n, 0);

	while ( m-- ) {
		int a, b, c, d;
		cin >> a >> b >> c >> d;

		for (int i = a - 1; i < c; i++) {
			// (b, d) cols
			//
			summary[i][b - 1]++;
			if ( d < n ) summary[i][d]--;
		}
	}

	FOR(r, n) {
		for (int c = 1; c < n; c++) {
			summary[r][c] = summary[r][c] + summary[r][c - 1];
		}
	}

	FOR(r, n) FOR(c, n) summary[r][c] %= 2;

	hopcroft_karp_matcher hkm;	

	int a, b; 
	do {

		auto edges { get_bipartite_edges(summary) };
		hkm.init(edges);
		cout << hkm.get_matching() << endl;

		if ( q == 0 ) break;
		q--;

		cin >> a >> b;
		summary[a - 1][b - 1] ^= 1;
	}

	while ( true );
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);

	go();

	return 0;
}