Submission #571440

#TimeUsernameProblemLanguageResultExecution timeMemory
571440duytuandao21Election (BOI18_election)C++14
28 / 100
3059 ms1144 KiB
#include<bits/stdc++.h> using namespace std; const int N = 2e6+7; int n,q; string s; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin>>n>>s>>q; while(q--) { int l,r; cin>>l>>r; l--; r--; string t = s; int cnt1 = 0, cnt2 = 0, res = 0; vector<bool> ok(n+1,0); for(int i=l;i<=r;i++) { if(t[i] == 'C') cnt1++; else cnt1--; if(cnt1 < 0) { t[i] = 'C'; ok[i] = 1; res++; cnt1++; } } //for(int i=0;i<n;i++) cout<<t[i]<<" "; cout<<cnt1; cout<<'\n'; for(int i=r;i>=l;i--) { if(ok[i]==1) continue; if(t[i] == 'C') cnt2++; else cnt2--; if(cnt2 < 0) { t[i] = 'C'; res++; cnt2++; } } cout<<res<<'\n'; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...