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 OYY LLONG_MAX
#define mod 998244353
#define faster ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define FOR for(int i=1;i<=n;i++)
#define mid (start+end)/2
#define lim 10005
#define fi first
#define se second
int32_t main(){
faster
int n;cin>>n;
string s;cin>>s;
int q;cin>>q;
while(q--){
vector<int> v(n,0);
int top=0;
int l,r;cin>>l>>r;
l--;r--;
for(int i=l;i<r;i++){
if(s[i]=='C')top++;
else{
top--;
if(top<0){
v[i]=1;
top++;
}
}
}
top=0;
for(int i=r;i>=l;i--){
//cout<<top<<endl;
if(s[i]=='C')top++;
else if(v[i]==1)continue;
else{
top--;
if(top<0){
top++;
v[i]=1;
}
}
}
top=0;
for(int i=l;i<=r;i++){
top+=v[i];
//cout<<v[i]<<endl;
}
cout<<top<<'\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... |