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 ll long long;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(0);
int n,q;
string s;
cin >> n >> s >> q;
for(int i = 0;i < q;i++){
int l,r;
cin >> l >> r;
vector <bool> vis(n,false);
int c = 0;
int t = 0;
for(int j = l-1; j < r;j++){
if(s.at(j) == 'C'){
c++;
}else{
t++;
if(t > c){
t--;
vis[j] = true;
}
}
}
c = 0;
t = 0;
for(int j = r-1; j > l;j--){
if(s.at(j) == 'C'){
c++;
}else if(!vis[j]){
t++;
if(t > c){
t--;
vis[j] = true;
}
}
}
int res = 0;
for(int j = l-1;j < r;j++){
if(vis[j]){
res++;
}
}
cout << res << "\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... |