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;
//1 => l-1~r
ll n,q;
string s;
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
cin>>n;
cin>>s;
cin>>q;
while(q--)
{
ll l,r;
cin>>l>>r;
vector<char> lf;
ll cnt = 0,ans = 0;
for(ll i=l-1;i<r;i++)
{
if(s[i]=='T'&&cnt==0)
ans++;
else
{
if(s[i]=='T')
cnt--;
else
cnt++;
lf.push_back(s[i]);
}
}
reverse(lf.begin(),lf.end());
cnt = 0;
for(char c:lf)
{
if(c=='T'&&cnt==0)
ans++;
else
{
if(c=='T')
cnt--;
else
cnt++;
}
}
cout<<ans<<"\n";
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |