Submission #1087070

#TimeUsernameProblemLanguageResultExecution timeMemory
1087070alexander707070Street Lamps (APIO19_street_lamps)C++14
40 / 100
323 ms16776 KiB
#include<bits/stdc++.h> #define MAXN 300007 using namespace std; struct ST{ int tree[4*MAXN],tree2[4*MAXN]; void update(int v,int l,int r,int pos,int val){ if(l==r){ tree[v]=tree2[v]=val; }else{ int tt=(l+r)/2; if(pos<=tt)update(2*v,l,tt,pos,val); else update(2*v+1,tt+1,r,pos,val); tree[v]=min(tree[2*v],tree[2*v+1]); tree2[v]=max(tree2[2*v],tree2[2*v+1]); } } int getmin(int v,int l,int r,int ll,int rr){ if(ll>rr)return 1; if(l==ll and r==rr){ return tree[v]; }else{ int tt=(l+r)/2; return min( getmin(2*v,l,tt,ll,min(tt,rr)) , getmin(2*v+1,tt+1,r,max(tt+1,ll),rr) ); } } int getmax(int v,int l,int r,int ll,int rr){ if(ll>rr)return 0; if(l==ll and r==rr){ return tree2[v]; }else{ int tt=(l+r)/2; return max( getmax(2*v,l,tt,ll,min(tt,rr)) , getmax(2*v+1,tt+1,r,max(tt+1,ll),rr) ); } } }st; int n,q,tim,x,l,r; char c[MAXN]; int last[MAXN],sum[MAXN]; string type; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin>>n>>q>>(c+1); for(int i=1;i<=n;i++){ if(c[i]=='1')st.update(1,1,n,i,1); } for(int i=1;i<=q;i++){ cin>>type; if(type=="toggle"){ cin>>x; if(c[x]=='0'){ c[x]='1'; last[x]=i; st.update(1,1,n,x,i+1); }else{ c[x]='0'; sum[x]+=i-last[x]; } }else{ cin>>l>>r; if(l+1<r){ int s=st.getmin(1,1,n,l,r-1); if(s==0)cout<<0<<"\n"; else cout<<i+1-st.getmax(1,1,n,l,r-1)<<"\n"; }else{ if(c[l]=='0')cout<<sum[l]<<"\n"; else cout<<sum[l]+i-last[l]<<"\n"; } } } return 0; }
#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...