#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,popcnt,abm,mmx,avx,avx2,fma")
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...)
#endif
const int N=500005;
int n,a[N],q;
bool chk[N];
string s;
int main(){
ios::sync_with_stdio(false); cin.tie(0);
cin>>n>>s>>q;
for(int i=1;i<=n;i++){
if(s[i-1]=='C') a[i]=1;
else a[i]=-1;
}
for(int l,r,t=1;t<=q;t++){
cin>>l>>r;
int s=0,ans=0,mn=0;
for(int i=l;i<=r;i++){
s+=a[i];
if(s<mn){
chk[i]=1;
mn=s;
ans++;
} else{
chk[i]=0;
}
}
s=mn=0;
for(int i=r;i>=l;i--) if(!chk[i]){
s+=a[i];
mn=min(mn,s);
}
ans-=mn;
cout<<ans<<"\n";
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2392 KB |
Output is correct |
2 |
Correct |
2 ms |
2396 KB |
Output is correct |
3 |
Correct |
2 ms |
2396 KB |
Output is correct |
4 |
Correct |
3 ms |
2396 KB |
Output is correct |
5 |
Correct |
2 ms |
2392 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2392 KB |
Output is correct |
2 |
Correct |
2 ms |
2396 KB |
Output is correct |
3 |
Correct |
2 ms |
2396 KB |
Output is correct |
4 |
Correct |
3 ms |
2396 KB |
Output is correct |
5 |
Correct |
2 ms |
2392 KB |
Output is correct |
6 |
Correct |
1311 ms |
2896 KB |
Output is correct |
7 |
Execution timed out |
3034 ms |
3136 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2392 KB |
Output is correct |
2 |
Correct |
2 ms |
2396 KB |
Output is correct |
3 |
Correct |
2 ms |
2396 KB |
Output is correct |
4 |
Correct |
3 ms |
2396 KB |
Output is correct |
5 |
Correct |
2 ms |
2392 KB |
Output is correct |
6 |
Correct |
1311 ms |
2896 KB |
Output is correct |
7 |
Execution timed out |
3034 ms |
3136 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |