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;
typedef long long ll;
const int N = 5e5+23;
int a[N],n;
bool ode[N];
string s;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int q;
cin >> n;
cin >> s;
for(int i = 1; i <= n; i++){
a[i] = (s[i-1] == 'C' ? 1 : -1);
}
cin >> q;
while(q--){
int l,r;
cin >> l >> r;
int sol = 0,bal = 0;
for(int i = l; i <= r; i++){
ode[i] = 0;
}
for(int i = l; i <= r; i++){
bal += a[i];
if(bal < 0){
ode[i] = 1;
sol++;
bal++;
}
}
bal = 0;
for(int i = r; i >= l; i--){
if(ode[i]){
continue;
}
bal += a[i];
if(bal < 0){
sol++;
bal++;
}
}
cout << sol << endl;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |