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;
// Hi
int main(){
ios::sync_with_stdio(0);cin.tie(0);
int n;
cin>>n;
string s;
cin>>s;
int q;
cin>>q;
while(q--){
int l,r;
cin>>l>>r;
l--,r--;
vector<bool> vis(n+1,0);
int cnt = 0;
int ans = 0;
for(int i=l;i<=r;i++){
cnt += (s[i] == 'C' ? 1 : -1);
//cout << i<<" "<<cnt<< '\n';
if(cnt < 0){
vis[i] = 1;
cnt++;
ans++;
}
}
cnt = 0;
for(int i=r;i>=l;i--){
if(vis[i])continue;
cnt += (s[i] == 'C' ? 1 : -1);
//cout << i<<" "<<cnt<< '\n';
if(cnt < 0){
cnt++;
ans++;
}
}
cout << ans << '\n';
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |