#pragma GCC optimize("Ofast") #pragma GCC optimization ("O3") #pragma GCC optimization ("unroll-loops") #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; #define mp make_pair #define eb emplace_back #define pb push_back #define e1 first #define e2 second #define uint unsigned int #define ll long long #define ull unsigned long long #define ld long double #define float long double #define size(x) (int)x.size() #define satori int testCases; cin>>testCases; while(testCases--) #define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0) #define all(r) begin(r),end(r) #define time chrono::high_resolution_clock().now().time_since_epoch().count() typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; mt19937 rng(chrono::high_resolution_clock().now().time_since_epoch().count()); /////////////////// #define debug if(false) /////////////////// const int MAXN=2e3+10; bitset<MAXN*MAXN> vis; int id[MAXN][MAXN]; int cnt[MAXN][MAXN]; int mt[MAXN*MAXN]; int col[MAXN*MAXN]; int n; bool path(int u){ if(vis[u]) return false; vis[u]=true; for(int v=u-(u-1)%n;v<u-(u-1)%n+n;v++){ if(col[v]==col[u]) continue; if(!mt[v]||path(mt[v])){ mt[u]=v; mt[v]=u; return true; } } for(int v=(u-1)%n+1;v<=n*n;v+=n){ if(col[v]==col[u]) continue; if(!mt[v]||path(mt[v])){ mt[u]=v; mt[v]=u; return true; } } return false; } int turbo(){ for(int i=1;i<=n*n;i++) mt[i]=0; int flow=0; bool nf=true; while(nf){ nf=false; for(int i=1;i<=n*n;i++) vis[i]=false; for(int i=1;i<=n*n;i++) if(!mt[i]&&path(i)) nf=true,flow++; } return flow; } int solve(){ return turbo(); } int32_t main() { fastio; int m,q,x1,x2,y1,y2; cin>>n>>m>>q; for(int i=0;i<m;i++){ cin>>x1>>y1>>x2>>y2; cnt[x1][y1]^=1; cnt[x1][y2+1]^=1; cnt[x2+1][y1]^=1; cnt[x2+1][y2+1]^=1; } for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) cnt[i][j]^=cnt[i-1][j]^cnt[i][j-1]^cnt[i-1][j-1],id[i][j]=j+(i-1)*n,col[id[i][j]]=cnt[i][j]; cout<<solve()<<'\n'; for(int i=0;i<q;i++){ cin>>x1>>y1; col[id[x1][y1]]^=1; cout<<solve()<<'\n'; } }
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 | #pragma GCC optimize("Ofast") #pragma GCC optimization ("O3") #pragma GCC optimization ("unroll-loops") #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; #define mp make_pair #define eb emplace_back #define pb push_back #define e1 first #define e2 second #define uint unsigned int #define ll long long #define ull unsigned long long #define ld long double #define float long double #define size(x) (int)x.size() #define satori int testCases; cin>>testCases; while(testCases--) #define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0) #define all(r) begin(r),end(r) #define time chrono::high_resolution_clock().now().time_since_epoch().count() typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; mt19937 rng(chrono::high_resolution_clock().now().time_since_epoch().count()); /////////////////// #define debug if(false) /////////////////// const int MAXN=2e3+10; bitset<MAXN*MAXN> vis; int id[MAXN][MAXN]; int cnt[MAXN][MAXN]; int mt[MAXN*MAXN]; int col[MAXN*MAXN]; int n; bool path(int u){ if(vis[u]) return false; vis[u]=true; for(int v=u-(u-1)%n;v<u-(u-1)%n+n;v++){ if(col[v]==col[u]) continue; if(!mt[v]||path(mt[v])){ mt[u]=v; mt[v]=u; return true; } } for(int v=(u-1)%n+1;v<=n*n;v+=n){ if(col[v]==col[u]) continue; if(!mt[v]||path(mt[v])){ mt[u]=v; mt[v]=u; return true; } } return false; } int turbo(){ for(int i=1;i<=n*n;i++) mt[i]=0; int flow=0; bool nf=true; while(nf){ nf=false; for(int i=1;i<=n*n;i++) vis[i]=false; for(int i=1;i<=n*n;i++) if(!mt[i]&&path(i)) nf=true,flow++; } return flow; } int solve(){ return turbo(); } int32_t main() { fastio; int m,q,x1,x2,y1,y2; cin>>n>>m>>q; for(int i=0;i<m;i++){ cin>>x1>>y1>>x2>>y2; cnt[x1][y1]^=1; cnt[x1][y2+1]^=1; cnt[x2+1][y1]^=1; cnt[x2+1][y2+1]^=1; } for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) cnt[i][j]^=cnt[i-1][j]^cnt[i][j-1]^cnt[i-1][j-1],id[i][j]=j+(i-1)*n,col[id[i][j]]=cnt[i][j]; cout<<solve()<<'\n'; for(int i=0;i<q;i++){ cin>>x1>>y1; col[id[x1][y1]]^=1; cout<<solve()<<'\n'; } } |