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;
cin >> N;
vector<int> s(N);
for (int i = 0; i < N; i++) {
char c;
cin >> c;
if (c == 'C') {
s[i] = 1;
}
else {
s[i] = -1;
}
}
int Q;
cin >> Q;
while (Q-->0) {
int l, r;
cin >> l >> r;
l--, r--;
unordered_set<int> touched;
int cur = 0;
for (int i = l; i <= r; i++) {
cur += s[i];
if (cur < 0) {
cur = 0;
touched.insert(i);
}
}
for (int i = r; i >= l; i--) {
if (!touched.count(i)) {
cur += s[i];
if (cur < 0) {
cur = 0;
touched.insert(i);
}
}
}
// for (auto i : touched) {
// cerr << i << " ";
// }
cout << touched.size() << '\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... |