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>
using namespace std;
int main() {
int n;
string s;
cin >> n >> s;
vector<int> c(n, 0);
int q;
cin >> q;
while (q--) {
int l, r;
cin >> l >> r;
l--;
fill(c.begin() + l, c.begin() + r, 0);
int b = 0;
for (int i = l; i < r; i++) {
if (s[i] == 'C') {
b++;
} else {
b--;
if (b < 0) {
b = 0;
c[i] = 1;
}
}
}
b = 0;
for (int i = r - 1; i >= l; i--) {
if (s[i] == 'C') {
b++;
} else if (!c[i]) {
b--;
if (b < 0) {
b = 0;
c[i] = 1;
}
}
}
int ans = count(c.begin() + l, c.begin() + r, 1);
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... |