#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
#define all(x) (x).begin(),(x).end()
#define X first
#define Y second
#define sep ' '
#define endl '\n'
#define debug(x) cerr << #x << ": " << x << endl;
const ll MAXN = 1e6 + 10;
int ps[MAXN], ss[MAXN];
string s;
inline void solve(string s) {
int n = s.size();
s = "#" + s;
for (int i = 1; i <= n; i++)
ps[i] = ps[i - 1] + (s[i] == 'T' ? 1 : -1);
ss[n + 1] = 0;
for (int i = n; i > 0; i--)
ss[i] = ss[i + 1] + (s[i] == 'T' ? 1 : -1);
int ans = 0;
for (int i = 1; i <= n; i++)
ans = max(ans, max(ps[i], 0) + max(ss[i + 1], 0));
cout << ans << endl;
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int n, q;
cin >> n >> s >> q;
while (q--) {
int l, r;
cin >> l >> r;
solve(s.substr(l - 1, r));
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
13 ms |
448 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
13 ms |
448 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
13 ms |
448 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |