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
#include <bits/stdc++.h>
#define int long long
#define mp make_pair
#define pb push_back
#define ld long double
#define pii pair<int,int>
#define sz(x) (int)x.size()
#define piii pair<pii,pii>
#define precise cout<<fixed<<setprecision(10)
#define st first
#define nd second
#define ins insert
#define vi vector<int>
#define BOOST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
const int MAX=2e3+5;
int pom[MAX][MAX];
int cntrow[MAX],cntcol[MAX];
int O[MAX];
int cols=0;
int rows=0;
int ile=0;
vi P[MAX*MAX];
int partner[MAX*MAX+MAX];
int n,m,q;
int ans=0;
int nrs=0;
int nr(int x,int y){
  return x*n+y;
}

bool match(int x)
{
    O[x]=nrs;
    for (auto it:P[x])
    {
        if (!partner[it])
        {
            partner[it]=x;
            //partnerka[x]=it;
            nrs++;
            return true;
        }
    }

    for (auto it:P[x])
    {
        if (O[partner[it]]!=nrs && match(partner[it]))
        {
            partner[it]=x;
            //partnerka[x]=it;
            nrs++;
            return true;
        }
    }
    return false;
}

void matching(){
  ans=0;
  for (int i=1;i<=n*n+5*n;i++)P[i].clear(),partner[i]=0,nrs=0,O[i]=0;
  for (int i=1;i<=n;i++){
    for (int j=1;j<=n;j++){
      for (int k=1;k<=n;k++){
        if (pom[i][j] && !pom[i][k])P[nr(i,j)].pb(nr(i,k));
      }
    }
  }
  
  for (int i=1;i<=n;i++){
    for (int j=1;j<=n;j++){
      for (int k=1;k<=n;k++){
        if (pom[j][i] && !pom[k][i])P[nr(j,i)].pb(nr(k,i));
      }
    }
  }
  
  for (int i=1;i<=n;i++){
    for (int j=1;j<=n;j++){
      if (pom[i][j]){
        if (match(nr(i,j)))ans++;  
      }
    }
  }
    
  cout<<ans<<"\n";
}

void change(int x,int y){
  if (pom[x][y]==1){
    cntrow[x]--;
    if (cntrow[x]==n-1)rows--;
    cntcol[y]--;
    if (cntcol[y]==n-1)cols--;
    ile--;
    pom[x][y]=0;
  }
  else{
    cntrow[x]++;
    if (cntrow[x]==n)rows++;
    cntcol[y]++;
    if (cntcol[y]==n)cols++;
    ile++;
    pom[x][y]=1;
  }
}
int32_t main(){
  BOOST;
  cin>>n>>m>>q;
  
  for (int i=1;i<=m;i++){
    int x1,y1,x2,y2;
    cin>>x1>>y1>>x2>>y2;
    pom[x1][y1]^=1;
    pom[x1][y2+1]^=1;
    pom[x2+1][y1]^=1;
    pom[x2+1][y2+1]^=1;
  }
  
  for (int i=1;i<=n;i++){
    for (int j=1;j<=n;j++){
      pom[i][j]^=pom[i][j-1];
      pom[i][j]^=pom[i-1][j];
      pom[i][j]^=pom[i-1][j-1];
    } 
  }
  
  /*
  for (int i=1;i<=n;i++){
    for (int j=1;j<=n;j++)cout<<pom[i][j]<<" ";
    cout<<"\n";
  }
  for (int i=1;i<=n;i++){
    for (int j=1;j<=n;j++){
      if (pom[i][j])
      pom[i][j]^=1,change(i,j);
    }
  }
  */
  //cout<<"TERAZ "<<ile<<" "<<cols<<" "<<rows<<" "<<n*n-ile<<" "<<ile-cols*rows<<"\n";
  matching();
  //cout<<min(n*n-ile,ile-cols*rows)<<"\n";
  for (int z=1;z<=q;z++){
    int x,y;
    cin>>x>>y;
    pom[x][y]^=1;
  //  for (int i=1;i<=n;i++){
  //   for (int j=1;j<=n;j++)cout<<pom[i][j]<<" ";
  //    cout<<"\n";
  //  }
    matching();
    //change(x,y);
    //cout<<min(n*n-ile,ile-cols*rows)<<"\n";
  }
  return 0; 
}