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>
using namespace std;
const int mx_N = 5e5 + 3;
int n, q;
string s;
int a[mx_N];
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> s;
for(int i = 0; i < n; ++i)
a[i + 1] = (s[i] == 'C') ? 1 : -1;
cin >> q;
for(int i = 0; i < q; ++i){
int l, r;
cin >> l >> r;
vector<int> v;
int sum = 0, answer = 0;
for(int j = l; j <= r; ++j){
if(!sum && a[j] == -1)
answer++;
else{
sum += a[j];
v.push_back(a[j]);
}
}
reverse(v.begin(), v.end());
sum = 0;
for(int x: v){
if(!sum && x == -1)
answer++;
else
sum += x;
}
cout << answer << "\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... |