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>
#define ll long long
#define st first
#define nd second
#define pii pair <ll, ll>
#define rep(i, n, m) for (ll i = (n); i <= (m); i ++)
#define rrep(i, n, m) for (ll i = (n); i >= (m); i --)
using namespace std;
const long long N = 1e6 + 5;
ll n, a[N], q;
bool del[N];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n;
rep(i, 1, n) {
char ch;
cin >> ch;
if (ch == 'T') a[i] = -1; else a[i] = 1;
}
cin >> q;
while (q --) {
int l, r;
cin >> l >> r;
int b = 0, ans = 0;
rep(i, l, r) {
b += a[i];
if (b < 0) b ++, ans ++, del[i] = true;
}
b = 0;
rrep(i, r, l) {
if (!del[i]) {
b += a[i];
if (b < 0) b ++, ans ++;
}
del[i] = false;
}
cout << ans << '\n';
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |