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
#include <iostream>
#include <queue>

using namespace std;

const int MAX_N = 2007;
int n, m, q;

bool type[MAX_N * MAX_N], visited[MAX_N * MAX_N];
int match[MAX_N * MAX_N], parent[MAX_N * MAX_N];
int matches = 0;

void ReadData();
void Match();
void Extend(int x, bool t);

int main() {
    ios_base::sync_with_stdio(0);
    
    ReadData();
    Match();
    printf("%d\n", matches);
    
    int a, b;
    while(q--) {
        cin >> a >> b;
        a--; b--;
        type[a * n + b] ^= 1;
        int mch = match[a * n + b];
        match[mch] = match[a * n + b] = -1;
        if(mch != -1) {
            matches--;
            Extend(mch, type[mch]);
        }
        Extend(a * n + b, type[a * n + b]);
        printf("%d\n", matches);
    }
    
    
    
    return 0;
}

int GetPath(int s, bool t) {
    fill(visited, visited + n * n, false);
    queue<int>q;
    q.push(s);
    parent[s] = -1;
    visited[s] = true;
    while(!q.empty()) {
        int x = q.front();
        q.pop();
        if(type[x] != t) {
            if(match[x] == -1)
                return x;
            if(!visited[match[x]]) {
                parent[match[x]] = x;
                visited[match[x]] = true;
                q.push(match[x]);
            }
        } else {
            int a = x / n;
            int b = x % n;
            for(int i = 0; i < n; i++) {
                if(type[a * n + i] != t && !visited[a * n + i]) {
                    visited[a * n + i] = true;
                    parent[a * n + i] = x;
                    q.push(a * n + i);
                }
                if(type[i * n + b] != t && !visited[i * n + b]) {
                    visited[i * n + b] = true;
                    parent[i * n + b] = x;
                    q.push(i * n + b);
                }
            }
            
        }
    }
    return -1;
}

void Match() {
    fill(match, match + n * n, -1);
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < n; j++) {
            if(type[i * n + j] == 1) {
                Extend(i * n + j, 1);
            }
        }
    }
}

void Extend(int beg, bool t) {
    int x = GetPath(beg, t);
    if(x == -1)
        return;
    matches++;
    while(parent[x] != -1) {
        if(type[x] != t) {
            match[x] = parent[x];
            match[parent[x]] = x;
        }
        x = parent[x];
    }
}

void ReadData() {
    int a, b, c, d;
    cin >> n >> m >> q;
    while(m--) {
        cin >> a >> b >> c >> d;
        for(int i = a - 1; i < c; i++)
            for(int j = b - 1; j < d; j++)
                type[i * n + j] ^= 1;
    }
}

/*
 4 3 4
 1 2 4 2
 3 1 3 4
 3 2 3 2
 4 4
 3 2
 4 3
 4 4
 
 7 2 0
 1 1 6 6
 2 2 7 7
 */