This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |