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;
const int N = 2e6+7;
int n,q;
string s;
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin>>n>>s>>q;
while(q--) {
int l,r;
cin>>l>>r; l--; r--;
string t = s;
int cnt1 = 0, cnt2 = 0, res = 0;
vector<bool> ok(n+1,0);
for(int i=l;i<=r;i++) {
if(t[i] == 'C') cnt1++; else cnt1--;
if(cnt1 < 0) {
t[i] = 'C';
ok[i] = 1;
res++;
cnt1++;
}
}
//for(int i=0;i<n;i++) cout<<t[i]<<" "; cout<<cnt1; cout<<'\n';
for(int i=r;i>=l;i--) {
if(ok[i]==1) continue;
if(t[i] == 'C') cnt2++; else cnt2--;
if(cnt2 < 0) {
t[i] = 'C';
res++;
cnt2++;
}
}
cout<<res<<'\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... |