Submission #710534

#TimeUsernameProblemLanguageResultExecution timeMemory
710534myrcellaDigital Circuit (IOI22_circuit)C++17
34 / 100
1159 ms13816 KiB
//by szh #include<bits/stdc++.h> using namespace std; #define fi first #define se second #define pii pair<int,int> #define pll pair<long long,long long> #define pb push_back #define debug(x) cerr<<#x<<"="<<x<<endl #define pq priority_queue #define inf 0x3f #define rep(i,a,b) for (int i=a;i<(b);i++) #define MP make_pair #define SZ(x) (int(x.size())) #define ll long long #define mod 1000002022 #define ALL(x) x.begin(),x.end() void inc(int &a,int b) {a=(a+b)%mod;} void dec(int &a,int b) {a=(a-b+mod)%mod;} int lowbit(int x) {return x&(-x);} ll p0w(ll base,ll p) {ll ret=1;while(p>0){if (p%2ll==1ll) ret=ret*base%mod;base=base*base%mod;p/=2ll;}return ret;} #include "circuit.h" const int maxn = 200010; int a[maxn]; vector <int> edge[maxn]; int NN,MM; pii tree[maxn*4]; int add[maxn*4]; int sum[maxn]; void initt(int c,int cl,int cr) { if (cl==cr) { tree[c] = {a[cl],a[cl]^1}; sum[c]=1; return; } int mid=cl+cr>>1; initt(c<<1,cl,mid); initt(c<<1|1,mid+1,cr); sum[c] = 2ll*sum[c<<1]*sum[c<<1|1]%mod; tree[c].fi = (1ll*tree[c<<1].fi*sum[c<<1|1]%mod + 1ll*tree[c<<1|1].fi*sum[c<<1]%mod)%mod; tree[c].se = (1ll*tree[c<<1].se*sum[c<<1|1]%mod + 1ll*tree[c<<1|1].se*sum[c<<1]%mod)%mod; // cout<<cl<<" "<<cr<<" "<<tree[c].fi<<" "<<tree[c].se<<endl; } void update(int c,int cl,int cr,int l,int r) { if (l<=cl and cr<=r) { add[c]^=1; swap(tree[c].fi,tree[c].se); return; } if (add[c]==1) { add[c<<1]^=1,add[c<<1|1]^=1; swap(tree[c<<1].fi,tree[c<<1].se); swap(tree[c<<1|1].fi,tree[c<<1|1].se); add[c] = 0; } int mid=cl+cr>>1; if (l<=mid) update(c<<1,cl,mid,l,r); if (r>mid) update(c<<1|1,mid+1,cr,l,r); tree[c].fi = (1ll*tree[c<<1].fi*sum[c<<1|1]%mod + 1ll*tree[c<<1|1].fi*sum[c<<1]%mod)%mod; tree[c].se = (1ll*tree[c<<1].se*sum[c<<1|1]%mod + 1ll*tree[c<<1|1].se*sum[c<<1]%mod)%mod; return; } void init(int N, int M, std::vector<int> P, std::vector<int> A) { NN=N,MM=M; rep(i,1,SZ(P)) { edge[P[i]].pb(i); } rep(i,0,SZ(A)) a[i+N]=A[i]; initt(1,N,N+M-1); } pii solve(int u) { if (SZ(edge[u])==0) { if (a[u]==0) return {0,1}; else return {1,0}; } vector <pii> ans; for (int v:edge[u]) { ans.pb(solve(v)); } vector <int> f; f.pb(1); rep(i,0,SZ(ans)) { f.pb(1ll*f.back()*ans[i].fi%mod); for (int j = i;j>=0;j--) { f[j] = 1ll*f[j]*ans[i].se%mod; if (j>0) inc(f[j],1ll*f[j-1]*ans[i].fi%mod); } } pii ret = {0,0}; rep(i,0,SZ(f)) { inc(ret.se,1ll*f[i]*(SZ(f)-1-i)%mod); inc(ret.fi,1ll*f[i]*i%mod); } return ret; } int count_ways(int L, int R) { if (NN<=1000) { rep(i,L,R+1) a[i]^=1; return solve(0).fi; } update(1,NN,NN+MM-1,L,R); return tree[1].fi; }

Compilation message (stderr)

circuit.cpp: In function 'void initt(int, int, int)':
circuit.cpp:40:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   40 |  int mid=cl+cr>>1;
      |          ~~^~~
circuit.cpp: In function 'void update(int, int, int, int, int)':
circuit.cpp:61:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   61 |  int mid=cl+cr>>1;
      |          ~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...