This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |