Submission #1023328

#TimeUsernameProblemLanguageResultExecution timeMemory
1023328kustizus즐거운 사진 수집 (JOI13_collecting)C++17
100 / 100
1405 ms90708 KiB
// #pragma GCC optimize("O3,unroll-loops") // #pragma GCC target("avx2,fma,bmi2,popcnt,lzcnt") #include <bits/stdc++.h> #define int long long using namespace std; mt19937_64 rnd(chrono::high_resolution_clock::now().time_since_epoch().count()); const int N=1048576; int n,q,now[25],b[N+5]; struct Segment_Tree{ bool Nam[2*N+5]; int ST[2*N+5],a[25]; void Build(){ Nam[1]=true; } void Update(int id, int l, int r, int pos){ if (l>pos || r<pos) return; if (l==r){ ST[id]=r-l+1-ST[id]; return; } int md=l+r>>1; Update(id<<1,l,md,pos); Update(id<<1|1,md+1,r,pos); ST[id]=ST[id<<1]+ST[id<<1|1]; } void Check(int id, int l, int r, int pos){ if ((id==1 && (!ST[id] || ST[id]==r-l+1)) || (id>1 && (!ST[id] || ST[id]==r-l+1) && (ST[id>>1] && ST[id>>1]!=(r-l+1)*2))){ if (!Nam[id]){ Nam[id]=true; ++a[b[r-l+1]]; } } else{ if (Nam[id]){ Nam[id]=false; --a[b[r-l+1]]; } } if (l>pos || r<pos) return; if (l==r) return; int md=l+r>>1; Check(id<<1,l,md,pos); Check(id<<1|1,md+1,r,pos); } } h,c; void Solve(){ cin>>n>>q; h.Build(); c.Build(); h.a[n]=c.a[n]=1; int mx=1<<n; b[1]=0; for (int i=2;i<=N;++i) b[i]=b[i/2]+1; now[0]=1; for (int i=1;i<=n;++i) now[i]=now[i-1]*4+1; while (q--){ int t,x; cin>>t>>x; if (!t){ h.Update(1,1,mx,x); h.Check(1,1,mx,x); } else{ c.Update(1,1,mx,x); c.Check(1,1,mx,x); } int ans=now[n],xx=0,yy=0; for (int i=n;i>=0;--i){ xx*=2,yy*=2; xx+=h.a[i]; yy+=c.a[i]; int d=(xx*c.a[i]+yy*h.a[i])-c.a[i]*h.a[i]; ans-=d*(now[i]-1); } cout<<ans<<"\n"; } } signed main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); // freopen ("FILE.INP","r",stdin); // freopen ("FILE.OUT","w",stdout); int t=1; // cin>>t; while (t--) Solve(); cerr<<"\nTIME: "<<1000*clock()/CLOCKS_PER_SEC<<"ms\n"; }

Compilation message (stderr)

collecting.cpp: In member function 'void Segment_Tree::Update(long long int, long long int, long long int, long long int)':
collecting.cpp:21:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   21 |         int md=l+r>>1;
      |                ~^~
collecting.cpp: In member function 'void Segment_Tree::Check(long long int, long long int, long long int, long long int)':
collecting.cpp:41:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   41 |         int md=l+r>>1;
      |                ~^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...