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"
#define int long long
using namespace std;
#ifdef Nero
#include "Deb.h"
#else
#define deb(...)
#endif
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; ++i) {
char c;
cin >> c;
a[i] = (c == 'C' ? 1 : -1);
}
int q;
cin >> q;
auto solve = [&](int l, int r) {
vector<int> nullified(n);
int sum = 0;
for (int i = l; i <= r; ++i) {
if (sum + a[i] < 0) nullified[i] = 1;
else sum += a[i];
}
sum = 0;
for (int i = r; i >= l; --i) {
if (nullified[i]) continue;
if (sum + a[i] < 0) nullified[i] = 1;
else sum += a[i];
}
return accumulate(nullified.begin(), nullified.end(), 0);
};
while (q--) {
int l, r;
cin >> l >> r;
cout << solve(l - 1, r - 1) << '\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... |