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 F first
#define S second
#define PB push_back
#define PF push_front
#define MP make_pair
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
const int maxn = 1e5 + 10;
const int mod = 1e9 + 7;
bool mark[maxn];
int main () {
int n, q;
string s;
cin >> n >> s >> q;
for (int i = 0; i < q; i++) {
memset (mark, 0, sizeof mark);
int l, r;
cin >> l >> r;
l --, r --;
int cnt = 0, ans = 0;
for (int j = l; j <= r; j++) {
if (s[j] == 'T' and cnt == 0) {
mark[j] = 1;
ans ++;
}
else if (s[j] == 'T')
cnt --;
else
cnt ++;
}
cnt = 0;
for (int j = r; j >= l; j--) {
if (mark[j])
continue;
if (s[j] == 'T' and cnt == 0) {
mark[j] = 1;
ans ++;
}
else if (s[j] == 'T')
cnt --;
else
cnt ++;
}
cout << ans << endl;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |