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>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
// #define int long long
#define endl '\n'
using namespace std;
using namespace __gnu_pbds;
using ordered_set = tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>;
signed main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int n,q;
cin>>n;
string s;
cin>>s;
vector<bool>v(n);
for(int i=0;i<n;i++)v[i]=(s[i]=='C');
vector<bool>V(n);
cin>>q;
while(q--){
int l,r;
cin>>l>>r;
l--;r--;
int cur=0,ans=0;
for(int i=l;i<=r;i++){
V[i]=0;
cur+=(v[i]?1:-1);
if(cur<0){
ans++;
V[i]=1;
cur=0;
}
}
cur=0;
for(int i=r;i>=l;i--){
if(V[i])continue;
cur+=(v[i]?1:-1);
if(cur<0){
ans++;
V[i]=1;
cur=0;
}
}
cout<<ans<<endl;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |