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 maxn = 7e4 + 5;
int arr[maxn], arr1[maxn], arr2[maxn];
string s;
int get(int l, int r){
arr1[l] = arr[l];
int mini = arr1[l];
for(int i=l+1; i<=r; i++){
arr1[i] = 0;
arr1[i] = arr[i] + arr1[i-1];
mini = min(mini, arr1[i]);
}
arr2[r] = arr[r];
mini = min(mini, arr2[r]);
for(int i=r-1; i>=l; i--){
arr2[i] = 0;
arr2[i] = arr[i] + arr2[i+1];
mini = min(mini, arr2[i]);
}return mini;
}
int main(){
//freopen("in.txt", "r", stdin);
int n;
cin>>n;
cin>>s;
for(int i=0; i<n; i++){
if(s[i] == 'C')arr[i] = 1;
else arr[i] = -1;
}
int q;
cin>>q;
while(q--){
int l, r;
cin>>l>>r;
cout<<abs(get(l-1, r-1))<<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... |