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;
const long long MX=500002;
string s;
int n,q;
int masnm[MX];
void zap(int l,int r,int nmzp)
{
int zrsum=0,kop=0;
for(int i=l;i<=r;i++)
{
if(s[i]=='C')
{
zrsum++;
}
else
{
if(zrsum==0)
{
masnm[i]=nmzp;
kop++;
}
else
{
zrsum--;
}
}
}
zrsum=0;
for(int i=r;i>=l;i--)
{
if(s[i]=='C')
{
zrsum++;
}
else
{
if(masnm[i]!=nmzp)
{
if(zrsum==0)
{
kop++;
}
else
{
zrsum--;
}
}
}
}
cout<<kop<<"\n";
return;
}
int main()
{
cin.tie(0);
ios_base::sync_with_stdio(0);
cin>>n>>s>>q;
s="*"+s;
for(int i=1;i<=q;i++)
{
int l,r;
cin>>l>>r;
zap(l,r,i);
}
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... |