#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
void solve(){
int n;
cin>>n;
string s;
cin>>s;
int q;
cin>>q;
while(q--){
int l,r;
cin>>l>>r;
--l; --r;
int cf=0, tf=0, remf=0;
for(int i = l; i <= r; i++){
if(s[i] == 'C'){
cf++;
}
else{
if(tf + 1 > cf) remf++;
else tf++;
}
}
int cb = 0, tb = 0, remb = 0;
for(int i = r; i >= l; i--){
if(s[i] == 'C'){
cb++;
}
else{
if(tb + 1 > cb) remb++;
else tb++;
}
}
cout<<max(remf, remb)<<"\n";
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int t = 1;
//cin>>t;
while(t--){
solve();
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |