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>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long int lld;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define trav(a,v) for(auto a:v)
void solve(){
/*freopen("cardgame.in", "r", stdin);
freopen("cardgame.out", "w", stdout);*/
int n,q;
cin>>n;
string s;
cin>>s;
cin>>q;
while(q--){
int l,r;
cin>>l>>r;
l--;r--;
lld sum=0;
lld pref=0;
lld ans=0;
rep(i,l,r+1){
lld x=1;
if(s[i]=='T')x*=-1;
sum+=x;
pref=max(0LL,pref+x);
ans=max(ans,pref);
}
cout<<ans-sum<<"\n";
}
}
int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.precision(16);
int tt=1;
//cin>>tt;
rep(test,0,tt){
solve();
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |