#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define show(x,y) cout << y << " " << #x << endl;
#define show2(x,y,i,j) cout << y << " " << #x << " " << j << " " << #i << endl;
#define show3(x,y,i,j,p,q) cout << y << " " << #x << " " << j << " " << #i << " " << q << " " << #p << endl;
#define show4(x,y) for(auto it:x) cout << it << " "; cout << #y << endl;
typedef pair<int,int>pii;
typedef pair<pii,pii>pi2;
void solve(){
int n,q;
cin >> n;
string s;
cin >> s;
int arr[n+1];
for(int x=1;x<=n;x++){
if(s[x-1]=='T')arr[x]=1;
else arr[x]=-1;
}
cin >> q;
int l,r;
for(int x=0;x<q;x++){
cin >> l >> r;
int maxi=0;
int counter=0;
for(int y=l;y<=r;y++){
counter+=arr[y];
maxi=max(maxi,counter);
}
counter=0;
for(int y=r;y>=l;y--){
counter+=arr[y];
maxi=max(maxi,counter);
}
cout << maxi << "\n";
}
}
int32_t main(){
ios::sync_with_stdio(0);
cin.tie(0);
//freopen("in.txt", "r", stdin);
int t=1;
//cin >> t;
while(t--){
solve();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |