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>
#define N 500005
using namespace std;
bool ok[N];
void solve(){
int n,q;
string s;
cin >> n >> s >> q;
s = "." + s;
for(int i = 1;i<=q;i++){
int l,r;
cin >> l >> r;
for(int j = l;j<=r;j++){
ok[j] = 0;
}
int mini = 0;
int now = 0;
for(int j = l;j<=r;j++){
if(s[j] == 'C')now++;
else now--;
if(now < mini){
ok[j] = 1;
mini = now;
}
}
mini = 0;
now = 0;
for(int j = r;j>=l;j--){
if(ok[j])continue;
if(s[j] == 'C')now++;
else now--;
if(now < mini){
ok[j] = 1;
mini = now;
}
}
int ans = 0;
for(int j = l;j<=r;j++){
ans += ok[j];
}
cout << ans << "\n";
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
#ifdef Local
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif
int t = 1;
//cin >> t;
while(t--){
solve();
}
#ifdef Local
cout << endl << fixed << setprecision(2) << 1000.0 * clock() / CLOCKS_PER_SEC << " milliseconds.";
#endif
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |