//#include<bits/stdc++.h>
#include <cstdio>
#include <iostream>
using namespace std;
const int N = 5e5 + 5, P = 1e9 + 7;
int n, q;
string v;
int a[N];
int main() {
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
cin >> n >> v >> q;
for (int i = 0; i < n; i++)
if (v[i] == 'T')
a[i] = 1;
else
a[i] = -1;
int l, r, ans, x;
while(q--) {
cin >> l >> r;
ans = x = 0;
l--;
for (int i = l; i < r; i++) {
x+=a[i];
ans = max(ans, x);
}
ans = x = 0;
for (int i = r - 1; i >= l; i--) {
x+=a[i];
ans = max(ans, x);
}
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... |