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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
#include <bits/stdc++.h>
#define MP make_pair
#define PB push_back
#define int long long
#define st first
#define nd second
#define rd third
#define FOR(i, a, b) for(int i =(a); i <=(b); ++i)
#define RE(i, n) FOR(i, 1, n)
#define FORD(i, a, b) for(int i = (a); i >= (b); --i)
#define REP(i, n) for(int i = 0;i <(n); ++i)
#define VAR(v, i) __typeof(i) v=(i)
#define FORE(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define __builtin_ctz __builtin_ctzll
#define __builtin_clz __builtin_clzll
#define __builtin_popcount __builtin_popcountll
using namespace std;
template<typename TH> void _dbg(const char* sdbg, TH h) { cerr<<sdbg<<"="<<h<<"\n"; }
template<typename TH, typename... TA> void _dbg(const char* sdbg, TH h, TA... t) {
  while(*sdbg != ',') { cerr<<*sdbg++; } cerr<<"="<<h<<","; _dbg(sdbg+1, t...);
}
#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#define debugv(x) {{cerr <<#x <<" = "; FORE(itt, (x)) cerr <<*itt <<", "; cerr <<"\n"; }}
#else
#define debug(...) (__VA_ARGS__)
#define debugv(x)
#define cerr if(0)cout
#endif
#define next ____next
#define prev ____prev
#define left ____left
#define hash ____hash
typedef long long ll;
typedef long double LD;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<pair<int, int> > VPII;
typedef vector<pair<ll, ll> > VPLL;

template<class C> void mini(C&a4, C b4){a4=min(a4, b4); }
template<class C> void maxi(C&a4, C b4){a4=max(a4, b4); }
template<class T1, class T2>
ostream& operator<< (ostream &out, pair<T1, T2> pair) { return out << "(" << pair.first << ", " << pair.second << ")";}
template<class A, class B, class C> struct Triple { A first; B second; C third;
  bool operator<(const Triple& t) const { if (st != t.st) return st < t.st; if (nd != t.nd) return nd < t.nd; return rd < t.rd; } };
template<class T> void ResizeVec(T&, vector<int>) {}
template<class T> void ResizeVec(vector<T>& vec, vector<int> sz) {
  vec.resize(sz[0]); sz.erase(sz.begin()); if (sz.empty()) { return; }
  for (T& v : vec) { ResizeVec(v, sz); }
}
typedef Triple<int, int, int> TIII;
template<class A, class B, class C>
ostream& operator<< (ostream &out, Triple<A, B, C> t) { return out << "(" << t.st << ", " << t.nd << ", " << t.rd << ")"; }
template<class T> ostream& operator<<(ostream& out, vector<T> vec) { out<<"("; for (auto& v: vec) out<<v<<", "; return out<<")"; }
template<class T> ostream& operator<<(ostream& out, set<T> vec) { out<<"("; for (auto& v: vec) out<<v<<", "; return out<<")"; }
template<class L, class R> ostream& operator<<(ostream& out, map<L, R> vec) { out<<"("; for (auto& v: vec) out<<v<<", "; return out<<")"; }

struct Ev {
  int typ, j1, j2; // typ = 1 dodaj, typ=0 - pytaj
};

struct Node {
  int to_push, c0, c1, wid;
};

const int UPP = 1 << 19;
int M;
Node drz[2 * UPP + 5];

void FlipNode(int node) {
  drz[node].to_push ^= 1;
  swap(drz[node].c0, drz[node].c1);
  return;
}

void Touch(int v) {
  assert(v < M);
  if (drz[v].to_push == 0) { return; }
  FOR (son, 2 * v, 2 * v + 1) {
    FlipNode(son);
  }
  drz[v].to_push = 0;
}

void FlipIntv(int bl, int br, int l, int r, int node) {
  if (br < l || r < bl) { return; }
  if (l <= bl && br <= r) {
    FlipNode(node);
    return;
  }
  int m = (bl + br) / 2;
  Touch(node);
  FlipIntv(bl, m, l, r, 2 * node);
  FlipIntv(m + 1, br, l, r, 2 * node + 1);
  drz[node].c0 = drz[2 * node].c0 + drz[2 * node + 1].c0;
  drz[node].c1 = drz[2 * node].c1 + drz[2 * node + 1].c1;
}
int ReadCell(int bl, int br, int node, int x) {
  if (bl == br) { return drz[node].c1; }
  Touch(node);
  int m = (bl + br) / 2;
  if (x <= m) { return ReadCell(bl, m, 2 * node, x); }
  return ReadCell(m + 1, br, 2 * node + 1, x);
}

const int N = 3e5 + 5;
pair<int, int> my_intv_aux[2][2 * N + 5];

struct N2 {
  int val, ma;
};
N2 drz2[2 * UPP + 5];
void Set(int i, int val) {
  i += M;
  drz2[i].val = val;
  drz2[i].ma = val;
  i /= 2;
  while (i) {
    drz2[i].ma = max(drz2[2 * i].ma, drz2[2 * i + 1].ma);
    i /= 2;
  }
}
void Add(int bl, int br, int l, int r, int node, int val) {
  if (r < bl || br < l) { return; }
  if (l <= bl && br <= r) {
    drz2[node].val += val;
    drz2[node].ma += val;
    return;
  }
  int m = (bl + br) / 2;
  Add(bl, m, l, r, 2 * node, val);
  Add(m + 1, br, l, r, 2 * node + 1, val);
  drz2[node].ma = drz2[node].val + max(drz2[2 * node].ma, drz2[2 * node + 1].ma);
}
void Add(int l, int r, int val) {
  if (l > r) { return; }
  Add(0, M - 1, l, r, 1, val);
}

int32_t main() {

  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(10);
  cerr << fixed << setprecision(10);
  cin.tie(0);
  //double beg_clock = 1.0 * clock() / CLOCKS_PER_SEC;
  
  //pair<int, int>*[] 
  pair<int, int>* my_intv[2] = {my_intv_aux[0] + N + 2, my_intv_aux[1] + N + 2};
  
  int n, rects, q;
  const int U = 3e5;
//#define TEST
#ifdef TEST
  n = 2000;
  rects = U;
  q = U;
#else
  cin>>n>>rects>>q;
#endif
  //vector<vector<int>> board(n + 2, VI(n + 2));
  //vector<vector<int>> id(n + 2, VI(n + 2));
  M = 1;
  while (M <= n + 5) {
    M *= 2;
  }
  
  vector<vector<vector<Ev>>> evs;
  ResizeVec(evs, {2, n + 2});
  RE (_, rects) {
    int i1, j1, i2, j2;
#ifdef TEST
    i1 = rand() % n + 1;
    i2 = rand() % n + 1;
    j1 = rand() % n + 1;
    j2 = rand() % n + 1;
    if (i1 > i2) { swap(i1, i2); }
    if (j1 > j2) { swap(j1, j2); }
#else
    cin>>i1>>j1>>i2>>j2;
#endif
    evs[0][i1].PB({1, j1, j2});
    evs[0][i2 + 1].PB({1, j1, j2});
    evs[1][j1].PB({1, i1, i2});
    evs[1][j2 + 1].PB({1, i1, i2});
  }
  VPII qs;
  RE (i, q) {
    int a, b;
#ifdef TEST
    a = rand() % n + 1;
    b = rand() % n + 1;
#else
    cin>>a>>b;
#endif
    qs.PB({a, b});
    evs[0][a].PB({0, b, -1});
  }
  map<PII, int> state;
  vector<VI> val_rzad(2, VI(n + 2));// val_col(n + 2);
  REP (tr, 2) {
    FORD (i, 2 * M, 1) {
      drz[i].to_push = drz[i].c0 = drz[i].c1 = 0;
      if (i >= M) {
        drz[i].c0 = (i < M + n);
      } else {
        drz[i].c0 = drz[2 * i].c0 + drz[2 * i + 1].c0;
      }
    }
    RE (i, n) {
      for (auto ev : evs[tr][i]) {
        if (ev.typ) {
          FlipIntv(1, M, ev.j1, ev.j2, 1);
        }
      }
      for (auto ev : evs[tr][i]) {
        if (ev.typ == 0) {
          state[{i, ev.j1}] = ReadCell(1, M, 1, ev.j1);
        }
      }
      val_rzad[tr][i] = drz[1].c1 - drz[1].c0;
    }
  }
  debug(val_rzad[0]);
  debug(val_rzad[1]);
  
  int cur = 0;
  RE (i, n) {
    REP (tr, 2) {
      cur -= val_rzad[tr][i];
    }
    //cur -= val_col[i];
    //cur -= val_row[i];
  }
  cur += 2 * n * n;
  vector<VI> sorted_rzad = val_rzad;
  //vector<int> sorted_rows = val_row;
  //vector<int> sorted_cols = val_col;
  REP (tr, 2) {
    sort(sorted_rzad[tr].begin() + 1, sorted_rzad[tr].begin() + n + 1, greater<int>());
  }
  //sort(sorted_rows.begin() + 1, sorted_rows.begin() + n + 1, greater<int>());
  //sort(sorted_cols.begin() + 1, sorted_cols.begin() + n + 1, greater<int>());
  int c = 0;
  int best = cur;
  debug(best);
  VI smallest_r_including_c(n + 2);
  //VI my_c(n + 2);
  //VPII intv(n + 2, PII{-1ll, -1ll}); // na przedziale [intv[i].st, intv[i].nd) sa wartosci i
  VI threshold(n + 2);
  Set(0, cur);
  threshold[0] = n;
  threshold[n + 1] = n - 2 * (n + 1);
  RE (r, n) {
    cur += 2 * sorted_rzad[0][r];
    cur += 4 * c;
    cur -= 2 * n;
    debug(cur);
    threshold[r] = n - 2 * r;
    while (c + 1 <= n && sorted_rzad[1][c + 1] > threshold[r]) {
      cur += 4 * r - 2 * n + 2 * sorted_rzad[1][c + 1];
      debug(cur);
      c++;
      smallest_r_including_c[c] = r;
    }
    Set(r, cur);
    //my_c[r] = c;
    assert(cur % 4 == 0);
    maxi(best, cur);
  }
  while (c + 1 <= n) {
    c++;
    smallest_r_including_c[c] = n + 1;
  }
  REP (tr, 2) {
    REP (i, 2 * N + 5) {
      my_intv_aux[tr][i] = PII{-1, -1};
    }
    RE (i, n) {
      if (my_intv[tr][sorted_rzad[tr][i]].st == -1) {
        my_intv[tr][sorted_rzad[tr][i]].st = i;
      }
      maxi(my_intv[tr][sorted_rzad[tr][i]].nd, i + 1);
    }
    my_intv[tr][n + 1] = {1, 1};
    FORD (i, n, -n) {
      if (my_intv[tr][i].st == -1) {
        my_intv[tr][i].st = my_intv[tr][i + 1].nd;
        my_intv[tr][i].nd = my_intv[tr][i].st;
      }
      //debug(i, my_intv[tr][i]);
    }
  }
      
  cout<<n * n - best / 4<<"\n";
  
  for (auto query : qs) {
    int i = query.st;
    int j = query.nd;
    vector<int> coords{i, j};
    int prv = state[{i, j}];
    int nxt = prv ^ 1;
    //debug(prv, nxt);
    VI place(2);
    int sign = 1;
    if (nxt) { // dodajemy
      REP (tr, 2) {
        int& v = val_rzad[tr][coords[tr]];
        place[tr] = my_intv[tr][v].st; // wez poczatek przedzialu
        assert(my_intv[tr][v + 2].nd == place[tr]); // upewnij sie ze sie zgadza z koncem lewego
        my_intv[tr][v].st++; // skurcz aktualny
        sorted_rzad[tr][place[tr]] += 2; // zaktualizuj wartosc w posortowanej
        v += 2; // zaktualizuj wartosc w tablicy po rzedach
        my_intv[tr][v].nd++; // dosun lewy
      }
      sign = 1;
    } else { // odejmujemy
      REP (tr, 2) {
        int& v = val_rzad[tr][coords[tr]];
        place[tr] = my_intv[tr][v].nd - 1; // wez koniec przedzialu
        //debug(tr, v, place[tr]);
        assert(my_intv[tr][v - 2].st == place[tr] + 1); // upewnij sie ze sie zgadza z poczatkiem prawego
        my_intv[tr][v].nd--; // skurcz aktualny
        sorted_rzad[tr][place[tr]] -= 2; // zaktualizuj wartosc w posortowanej
        v -= 2; // zaktualizuj wartosc w tablicy
        my_intv[tr][v].st--; // dosun prawy
      }
      sign = -1;
    }
    
    assert(place[0] > 0);
    int pos_c = smallest_r_including_c[place[1]];
    debug(place, pos_c);
    Add(place[0], n, 2 * sign);
    Add(0, place[0] - 1, -2 * sign);
    Add(pos_c, n, 2 * sign);
    Add(0, pos_c - 1, -2 * sign);
    int val_c = val_rzad[1][coords[1]];
    if (nxt) { // jak dodaje to moge chciec wczesniej
      if (threshold[pos_c - 1] < val_c) {
        Add(pos_c - 1, pos_c - 1, 2 * val_c - 2 * threshold[pos_c - 1]);
        smallest_r_including_c[place[1]]--;
      }
    } else { // moge chciec pozniej
      if (threshold[pos_c] > val_c) {
        Add(pos_c, pos_c, 2 * threshold[pos_c] - 2 * val_c);
        smallest_r_including_c[place[1]]++;
      }
    }
    state[{i, j}] = nxt;
    best = drz2[1].ma;
    assert(best % 4 == 0);
    cout<<n * n - best / 4<<"\n";
  }
    
  
    
    
      
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  return 0;
}