제출 #1191315

#제출 시각아이디문제언어결과실행 시간메모리
1191315vnedu즐거운 사진 수집 (JOI13_collecting)C++17
100 / 100
2140 ms210576 KiB
#include<bits/stdc++.h> using namespace std; typedef long long ll; template<class T> bool maximize(T &a, const T &b){ return (a < b ? a = b, 1 : 0); } template<class T> bool minimize(T &a, const T &b){ return (a > b ? a = b, 1 : 0); } #define fi first #define se second #define pb push_back #define ii pair<int, int> #define all(x) x.begin(), x.end() #define TASK "nonsense" /// end of template /// const int mb = 20; int n,q; struct segtree { bool state[(1<<mb)+1]; int t[1<<mb][mb+2],left[mb+2],right[mb+2],cur; void build(int id, int l, int r, int layer) { if(layer==n-1) { left[n]=0,left[n+1]=state[l]; right[n]=0,right[n+1]=state[r]; } else { int mid((l+r)>>1); build(id<<1,l,mid,layer+1); build(id<<1|1,mid+1,r,layer+1); for(int k=layer;k<=n+1;++k) left[k]=t[id<<1][k],right[k]=t[id<<1|1][k]; } if(min(left[n+1],right[n+1])>=0 && left[n+1]==right[n+1]) cur=left[n+1]; else cur=-1; t[id][n+1]=cur; if(cur<0) { for(int k=layer+1;k<=n;++k) t[id][k]=left[k]+right[k]; } else { for(int k=layer+1;k<=n;++k) t[id][k]=(1<<(k-layer)); } } void toggle(int id, int l, int r, int x, int layer) { if(layer==n-1) { if(x==r) state[r]^=1; else state[l]^=1; left[n]=0,left[n+1]=state[l]; right[n]=0,right[n+1]=state[r]; } else { int mid((l+r)>>1); if(x<=mid) toggle(id<<1,l,mid,x,layer+1); else toggle(id<<1|1,mid+1,r,x,layer+1); for(int k=layer;k<=n+1;++k) left[k]=t[id<<1][k],right[k]=t[id<<1|1][k]; } if(min(left[n+1],right[n+1])>=0 && left[n+1]==right[n+1]) cur=left[n+1]; else cur=-1; // cout<<l<<' '<<r<<' '<<cur<<'\n'; t[id][n+1]=cur; if(cur<0) { for(int k=layer+1;k<=n;++k) t[id][k]=left[k]+right[k]; } else { for(int k=layer+1;k<=n;++k) t[id][k]=(1<<(k-layer)); } // cout<<l<<' '<<r<<' '<<t[id][n+1]<<'\n'; } } t[2]; void solve() { cin>>n>>q; t[0].build(1,1,1<<n,0); t[1].build(1,1,1<<n,0); while(q--) { bool gogo; cin>>gogo; int x; cin>>x; t[gogo].toggle(1,1,1<<n,x,0); ll ans=0; for(int k=0;k<=n;++k) { int cnt=(1<<k); ans+=cnt*1LL*cnt; ans-=t[0].t[1][k]*1LL*t[1].t[1][k]; } cout<<ans<<'\n'; } // cout<<t[1].t[3][n+1]<<'\n'; // cout<<t[1].t[1][1]; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); // freopen(TASK".inp","r",stdin); // freopen(TASK".out","w",stdout); int testcase=1; // cin>>testcase; while (testcase--) solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...