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 N = 2e3 + 2;
int n, q, u[N];
string s;
int main(){
cin >> n >> s >> q;
s = ' ' + s;
while(q --){
int l, r, ans = 0, a = 0, b = 0;
cin >> l >> r;
for(int i = l; i <= r; i ++){
if(s[i] == 'C')
a ++;
else
b ++;
if(b > a){
b --;
u[i] = 1;
ans ++;
}
}
a = b = 0;
for(int i = r; i >= l; i --){
if(s[i] == 'C')
a ++;
else
if(!u[i])
b ++;
if(b > a){
b --;
ans ++;
}
u[i] = 0;
}
cout << ans << endl;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |