#include <bits/stdc++.h>
#define ar array
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll;
int main() {
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int n, q;
string s;
cin >> n >> s >> q;
s = "1" + s;
vector <int> a(n + 1);
for (int i = 1; i <= n; i++)
a[i] = s[i] == 'C' ? 1 : -1;
while (q--) {
int l, r, sm = 0, ans = 0;
cin >> l >> r;
vector <int> pos(n + 1, 1);
for (int i = l; i <= r; i++) {
sm += a[i];
if (sm < 0)
sm++, pos[i] = 0, ans++;
}
sm = 0;
for (int i = r; i >= l; i--) {
sm += a[i] * pos[i];
if (sm < 0)
sm++, 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... |