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>
#define ll long long
#define endl '\n'
#define pb push_back
using namespace std;
int main()
{
ll n,q;
string s;
cin>>n>>s>>q;
while(q--)
{
ll x,y;
cin>>x>>y;
x--;
y--;
ll arr[n]={};
ll t=0,c=0;
for(int i=x;i<=y;i++)
{
if(s[i]=='C')c++;
else t++;
if(t>c)
{
arr[i]++;
t--;
}
}
t=0,c=0;
for(int i=y;i>=x;i--)
{
if(s[i]=='C')c++;
else if(arr[i]==0)t++;
if(t>c)
{
arr[i]++;
t--;
}
}
ll ans=0;
for(int i=0;i<n;i++)
if(arr[i]>0)ans++;
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... |