This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize("O3")
//#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,popcnt,abm,mmx,avx,avx2,fma")
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...)
#endif
const int N=500005;
int n,a[N],q;
bool chk[N];
string s;
int main(){
ios::sync_with_stdio(false); cin.tie(0);
cin>>n>>s>>q;
for(int i=1;i<=n;i++){
if(s[i-1]=='C') a[i]=1;
else a[i]=-1;
}
for(int l,r,t=1;t<=q;t++){
cin>>l>>r;
int s=0,ans=0,mn=0;
for(int i=l;i<=r;i++){
if(s+a[i]<0){
chk[i]=1;
ans++;
} else{
s+=a[i];
chk[i]=0;
}
}
s=0;
for(int i=r;i>=l;i--) if(!chk[i]){
s+=a[i];
mn=min(mn,s);
}
ans-=mn;
cout<<ans<<"\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... |