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;
int main()
{
cin.sync_with_stdio(false);
cin.tie(0);
int n, q;
string s;
cin>>n;
cin>>s;
cin>>q;
for(int i = 0; i < q; i++){
int l, r;
cin>>l>>r;
int x = 0, meg = 0;
vector<bool> kell(n, false);
for(int j = l-1; j < r; j++){
if(s[j] == 'T' && x > 0){
x--;
kell[j] = true;
} else if(s[j] == 'C')
x++;
else
meg++;
}
x = 0;
int legk = 0;
for(int j = r-1; j >= l-1; j--){
if(s[j] == 'T' && kell[j])
x--;
else if(s[j] == 'C')
x++;
legk = min(legk, x);
}
cout<<meg-legk<<"\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... |