Submission #902851

#TimeUsernameProblemLanguageResultExecution timeMemory
90285112345678Election (BOI18_election)C++17
28 / 100
3089 ms3416 KiB
#include <bits/stdc++.h> using namespace std; const int nx=5e5+5; int n, v[nx], w[nx], q, l, r, cnt, ans; string s; int main() { cin.tie(NULL)->sync_with_stdio(false); cin>>n>>s; for (int i=1; i<=n; i++) v[i]=s[i-1]=='C'; cin>>q; while (q--) { cin>>l>>r; cnt=ans=0; for (int i=l; i<=r; i++) { if (v[i]) w[i]=v[i], cnt++; else if (cnt==0) w[i]=2, ans++; else w[i]=0, cnt--; } cnt=0; for (int i=r; i>=l; i--) { if (w[i]==1) cnt++; else if (w[i]==2) continue; else if (w[i]==0&&cnt==0) ans++; else cnt--; } cout<<ans<<'\n'; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...