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 int long long
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
signed main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
int n,q;
cin>>n;
string s;
cin>>s;
cin>>q;
while(q--){
int l,r;
cin>>l>>r;l--;r--;
int ans=0;
vector <int> nu(s.size(),-1);
int cnt2=0,cnt1=0;
for(int i=l;i<=r;i++){
if(s[i]=='C')cnt1++;
else cnt2++;
if(cnt2>cnt1){
nu[i]=0;
ans++;
cnt2--;
}
}
cnt2=0;cnt1=0;
for(int i=r;i>=l;i--){
if(s[i]=='C')cnt1++;
else if(s[i]=='T' && nu[i]==-1)cnt2++;
if(cnt2>cnt1){
nu[i]=0;
ans++;
cnt2--;
}
}
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... |