#include "bits/stdc++.h"
using namespace std;
const int maxn = 7e4 + 5;
int arr[maxn], arr1[maxn], arr2[maxn], n;
string s;
int solve(int l, int r){
int cnt = 0;
int ret = 0;
for(int i=l; i<=r; i++){
cnt += arr[i];
if(cnt < 0){
ret++;
cnt++;
}
}
int ret1 = 0;
cnt = 0;
for(int i=r; i>=l; i--){
cnt += arr[i];
if(cnt < 0){
ret1++;
cnt++;
}
}
return max(ret, ret1);
}
int main(){
//freopen("in.txt", "r", stdin);
cin>>n;
cin>>s;
for(int i=1; i<=n; i++){
if(s[i-1] == 'C')arr[i] = 1;
else arr[i] = -1;
}
int q;
cin>>q;
while(q--){
int l, r;
cin>>l>>r;
cout<<solve(l, r)<<endl;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
9 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
9 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
9 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |