Submission #956529

#TimeUsernameProblemLanguageResultExecution timeMemory
956529moonrabbit2Election (BOI18_election)C++17
28 / 100
3034 ms3136 KiB
#pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,popcnt,abm,mmx,avx,avx2,fma") #include <bits/stdc++.h> using namespace std; #ifdef LOCAL #include "debug.h" #else #define debug(...) #endif const int N=500005; int n,a[N],q; bool chk[N]; string s; int main(){ ios::sync_with_stdio(false); cin.tie(0); cin>>n>>s>>q; for(int i=1;i<=n;i++){ if(s[i-1]=='C') a[i]=1; else a[i]=-1; } for(int l,r,t=1;t<=q;t++){ cin>>l>>r; int s=0,ans=0,mn=0; for(int i=l;i<=r;i++){ s+=a[i]; if(s<mn){ chk[i]=1; mn=s; ans++; } else{ chk[i]=0; } } s=mn=0; for(int i=r;i>=l;i--) if(!chk[i]){ s+=a[i]; mn=min(mn,s); } ans-=mn; cout<<ans<<"\n"; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...