#pragma GCC optimize "Ofast,unroll-loops"
#pragma GCC target "avx,avx2,sse4"
#include <bits/stdc++.h>
using namespace std;
int constexpr N = 1<<19;
int upd[N];
char s[N];
int ss[N];
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int n; cin >> n >> s;
for (int i = 0; i < n; ++i) ss[i] = s[i] == 'C' ? 1 : -1;
int q; cin >> q;
for (int qi = 1; qi <= q; ++qi) {
int l, r; cin >> l >> r; --l;
int ans = 0;
for (int i = l, c = 0; i < r; ++i) {
c += ss[i];
if (c < 0) ++c, ++ans, upd[i] = qi;
}
for (int i = r-1, c = 0; i >= l; --i) {
c += ss[i] + (upd[i] == qi);
if (c < 0) ++c, ++ans;
}
cout << ans << '\n';
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
388 KB |
Output is correct |
2 |
Correct |
3 ms |
340 KB |
Output is correct |
3 |
Correct |
2 ms |
340 KB |
Output is correct |
4 |
Correct |
3 ms |
360 KB |
Output is correct |
5 |
Correct |
2 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
388 KB |
Output is correct |
2 |
Correct |
3 ms |
340 KB |
Output is correct |
3 |
Correct |
2 ms |
340 KB |
Output is correct |
4 |
Correct |
3 ms |
360 KB |
Output is correct |
5 |
Correct |
2 ms |
340 KB |
Output is correct |
6 |
Correct |
1454 ms |
1148 KB |
Output is correct |
7 |
Execution timed out |
3063 ms |
952 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
388 KB |
Output is correct |
2 |
Correct |
3 ms |
340 KB |
Output is correct |
3 |
Correct |
2 ms |
340 KB |
Output is correct |
4 |
Correct |
3 ms |
360 KB |
Output is correct |
5 |
Correct |
2 ms |
340 KB |
Output is correct |
6 |
Correct |
1454 ms |
1148 KB |
Output is correct |
7 |
Execution timed out |
3063 ms |
952 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |