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>
#define long long ll
using namespace std;
const int MAX_N=1e6;
void solve() {
int n;
cin >> n;
string s;
cin >> s;
int q;
cin >> q;
while(q--) {
int l,r;
cin >> l >> r;
--l;
int cnt=0, ans=0;
string tmp=s;
for(int i=l; i<r; ++i) {
if(s[i]=='C') ++cnt;
else if(s[i]=='T') --cnt;
if(cnt<0) {
++cnt;
++ans;
tmp[i]='X';
}
}
cnt=0;
for(int i=r-1; i>=l; --i) {
if(tmp[i]=='C') ++cnt;
else if(tmp[i]=='T') --cnt;
if(cnt<0) {
++cnt;
++ans;
}
}
cout << ans << endl;
}
}
int main()
{
int T=1;
while(T--) solve();
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... |