Submission #861390

#TimeUsernameProblemLanguageResultExecution timeMemory
861390maks007Election (BOI18_election)C++14
28 / 100
3069 ms1128 KiB
#include "bits/stdc++.h" using namespace std; #define int long long signed main () { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; string str; cin >> str; int q; cin >> q; while(q --) { int l, r; cin >> l >> r; l --, r --; int bal = 0; set <int> s1, s2; for(int i = l; i <= r; i ++) { if(str[i] == 'C') bal ++; else if(bal == 0) { s1.insert(i); }else bal --; } bal = 0; for(int i = r; i >= l; i --) { if(s1.count(i)) continue; if(str[i] == 'C') bal ++; else if(bal == 0) { s2.insert(i); }else bal --; } for(auto i : s2) s1.insert(i); cout << s1.size() << "\n"; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...