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;
int main()
{
int n,q;
cin>>n;
string s;
cin>>s;
s="$"+s;
cin>>q;
for(int i=0;i<q;i++)
{
int x,y;
cin>>x>>y;
int sum=0;
int counter=0;
for(int j=x;j<=y;j++)
{
if(sum==0 && s[j]=='T'){counter++;s[j]='F';}
else if(s[j]=='T')sum--;
else sum++;
}
sum=0;
for(int j=y;j>=x;j--)
{
if(sum==0 && s[j]=='T'){counter++;s[j]='F';}
else if(s[j]=='T')sum--;
else if(s[j]=='C')sum++;
}
for(int j=x;j<=y;j++)
{
if(s[j]=='F')s[j]='T';
}
cout<<counter<<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... |