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;
typedef long long ll;
int main ()
{
ll n; cin>>n;
string s; cin>>s;
ll q; cin>>q;
while(q--)
{
ll l,r;
cin>>l>>r; l--;r--;
ll cc=0; ll ct=0;
ll ans1=0;
for (int i=l;i<=r;i++)
{
if (s[i]=='C')
cc++;
else
{
if (ct==cc)
{
ans1++;
}
else
{
ct++;
}
}
}
ct=0; cc=0;
ll ans2=0;
for (int i=r;i>=l;i--)
{
if (s[i]=='C')
cc++;
else
{
if (ct==cc)
{
ans2++;
}
else
{
ct++;
}
}
}
cout<<max(ans1,ans2)<<endl;
}
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... |