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;
signed main() {
int n,q; cin>>n;
string s; cin>>s;
cin>>q;
while(q--) {
int l,r; cin>>l>>r;
l--,r--;
vector<bool>v(n, 0);
int cnt = 0;
int ans = 0;
for(int i = l ; i <= r ; i++) {
if(s[i] == 'T') cnt--;
else cnt++;
if(cnt < 0) v[i] = 1, ans++, cnt++;
}
cnt = 0;
for(int i = r ; i >= l ; i--) {
if(s[i] == 'C') cnt++;
else if(!v[i]) cnt--;
if(cnt < 0) ans++, cnt++;
}
cout << ans << '\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... |