#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 |
1 |
Incorrect |
372 ms |
748 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
372 ms |
748 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
372 ms |
748 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |