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 mp make_pair
#define all(a) a.begin(), a.end()
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
int get(string s) {
int n = s.size();
vector<bool> nulli(n);
int bal = 0;
for (int i = 0; i < n; i++) {
if (nulli[i])
continue;
if (bal == 0 and s[i] == 'T')
nulli[i] = true;
else if (s[i] == 'T')
bal--;
else
bal++;
}
bal = 0;
for (int i = n - 1; i >= 0; i--) {
if (nulli[i])
continue;
if (bal == 0 and s[i] == 'T')
nulli[i] = true;
else if (s[i] == 'T')
bal--;
else
bal++;
}
return count(all(nulli), true);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
string s;
cin >>s;
int q;
cin >> q;
while (q--) {
int l, r;
cin >> l >> r; r--, l--;
cout << get(s.substr(l, r - l + 1)) << "\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... |