#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define mp make_pair #define pb push_back #define pf push_front #define eb emplace_back #define st first #define nd second #define vt vector #define DEBUG if(1) #define VAR(__var) #__var << ": " << __var << " " #define PARA(__var) #__var << ": " << __var.first << ", " << __var.second << " " #define FOR(__var, __start, __end) for(int __var=__start; __var<__end; ++__var) #define FORB(__var, __start, __end) for(int __var=__start; __var>__end; --__var) #define all(__var) (__var).begin(),(__var).end() #define rall(__var) (__var).rbegin(),(__var).rend() #define sz(__var) (int)(__var).size() #define satori(__var) int __var; cin>>__var; while(__var--) using namespace std; using namespace __gnu_pbds; template <typename T> using ord_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>; typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair<int,int> pii; typedef pair<ll,ll> pll; const int INF = 1e9+2137; int MAXN; vt<vt<int>> g; vt<bool> vis; vt<int> match; int n, m, q; inline int v(int l, int r) { return l*n+r; } bool turbo(int v) { vis[v] = 1; for(auto u : g[v]) if(match[u] == -1) { match[u] = v; match[v] = u; return 1; } for(auto u : g[v]) if(!vis[match[u]] && turbo(match[u])) { match[u] = v; match[v] = u; return 1; } return 0; } void solve() { fill(all(match), -1); bool kul = 1; while(kul) { fill(all(vis), 0); kul = 0; FOR(v, 0, MAXN) if(match[v] == -1 && turbo(v)) kul = 1; } int res = 0; FOR(i, 0, MAXN) if(match[i]!=-1) ++res; cout << res/2 << '\n'; } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m >> q; vt<vt<int>> a(n, vt<int>(n)); MAXN = v(n-1, n-1)+1; FOR(k, 0, m) { int x1, x2, y1, y2; cin >> x1 >> y1 >> x2 >> y2; x1--, y1--; FOR(i, x1, x2) FOR(j, y1, y2) a[i][j] ^= 1; } g.resize(MAXN); vis.resize(MAXN); match.resize(MAXN); FOR(i, 0, n) FOR(j, 0, n) { if(a[i][j]) { FOR(k, 0, n) { if(!a[i][k]) g[v(i, j)].pb(v(i, k)), g[v(i, k)].pb(v(i, j)); if(!a[k][j]) g[v(i, j)].pb(v(k, j)), g[v(k, j)].pb(v(i, j)); } } } solve(); while(q--) { int x, y; cin >> x >> y; x--, y--; a[x][y] ^= 1; FOR(i, 0, MAXN) g[i].clear(); FOR(i, 0, n) FOR(j, 0, n) { if(a[i][j]) { FOR(k, 0, n) { if(!a[i][k]) g[v(i, j)].pb(v(i, k)), g[v(i, k)].pb(v(i, j)); if(!a[k][j]) g[v(i, j)].pb(v(k, j)), g[v(k, j)].pb(v(i, j)); } } } solve(); } return 0; }
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 | #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define mp make_pair #define pb push_back #define pf push_front #define eb emplace_back #define st first #define nd second #define vt vector #define DEBUG if(1) #define VAR(__var) #__var << ": " << __var << " " #define PARA(__var) #__var << ": " << __var.first << ", " << __var.second << " " #define FOR(__var, __start, __end) for(int __var=__start; __var<__end; ++__var) #define FORB(__var, __start, __end) for(int __var=__start; __var>__end; --__var) #define all(__var) (__var).begin(),(__var).end() #define rall(__var) (__var).rbegin(),(__var).rend() #define sz(__var) (int)(__var).size() #define satori(__var) int __var; cin>>__var; while(__var--) using namespace std; using namespace __gnu_pbds; template <typename T> using ord_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>; typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair<int,int> pii; typedef pair<ll,ll> pll; const int INF = 1e9+2137; int MAXN; vt<vt<int>> g; vt<bool> vis; vt<int> match; int n, m, q; inline int v(int l, int r) { return l*n+r; } bool turbo(int v) { vis[v] = 1; for(auto u : g[v]) if(match[u] == -1) { match[u] = v; match[v] = u; return 1; } for(auto u : g[v]) if(!vis[match[u]] && turbo(match[u])) { match[u] = v; match[v] = u; return 1; } return 0; } void solve() { fill(all(match), -1); bool kul = 1; while(kul) { fill(all(vis), 0); kul = 0; FOR(v, 0, MAXN) if(match[v] == -1 && turbo(v)) kul = 1; } int res = 0; FOR(i, 0, MAXN) if(match[i]!=-1) ++res; cout << res/2 << '\n'; } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m >> q; vt<vt<int>> a(n, vt<int>(n)); MAXN = v(n-1, n-1)+1; FOR(k, 0, m) { int x1, x2, y1, y2; cin >> x1 >> y1 >> x2 >> y2; x1--, y1--; FOR(i, x1, x2) FOR(j, y1, y2) a[i][j] ^= 1; } g.resize(MAXN); vis.resize(MAXN); match.resize(MAXN); FOR(i, 0, n) FOR(j, 0, n) { if(a[i][j]) { FOR(k, 0, n) { if(!a[i][k]) g[v(i, j)].pb(v(i, k)), g[v(i, k)].pb(v(i, j)); if(!a[k][j]) g[v(i, j)].pb(v(k, j)), g[v(k, j)].pb(v(i, j)); } } } solve(); while(q--) { int x, y; cin >> x >> y; x--, y--; a[x][y] ^= 1; FOR(i, 0, MAXN) g[i].clear(); FOR(i, 0, n) FOR(j, 0, n) { if(a[i][j]) { FOR(k, 0, n) { if(!a[i][k]) g[v(i, j)].pb(v(i, k)), g[v(i, k)].pb(v(i, j)); if(!a[k][j]) g[v(i, j)].pb(v(k, j)), g[v(k, j)].pb(v(i, j)); } } } solve(); } return 0; } |