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;
const int mx_N = 5e5 + 3;
int n, q;
string s;
int a[mx_N];
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> s;
for(int i = 0; i < n; ++i)
a[i + 1] = (s[i] == 'C') ? 1 : -1;
cin >> q;
for(int i = 0; i < q; ++i){
int lq, rq;
cin >> lq >> rq;
int sum = 0, l = 0, r = 0;
for(int i = lq; i <= rq; ++i){
if(a[i] == 1){
if(r)
r--;
else
sum++;
}
else if(a[i] == -1){
if(sum)
r++;
else
l++;
}
}
cout << l + r << "\n";
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |