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
void solve(vector<int>ar){
int n=ar.size()-1;
vector<int>br=ar;
priority_queue<int>pq;
int tot=0;
int ret=0;
for(int i=1;i<=n;i++){
tot+=ar[i];
if(tot<0){
tot+=1;br[i]=0;ret++;
}
}
tot=0;
for(int i=n;i>=1;i--){
tot+=br[i];
if(tot<0){
tot+=1;br[i]=0;ret++;
}
}
cout<<ret<<endl;
}
int n;int Q;
int ar[500005];
signed main(){
cin>>n;
{
string s;
cin>>s;
for(int i=0;i<n;i++){
if(s[i]=='C'){
ar[i+1]=1;
}else{
ar[i+1]=-1;
}
}
}
cin>>Q;
while(Q--){
int l;int r;
cin>>l>>r;
vector<int>vc;
vc.push_back(0);
for(int i=l;i<=r;i++){
vc.push_back(ar[i]);
}
solve(vc);
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |