#include <bits/stdc++.h>
using namespace std;
#define int long long
#define OYY LLONG_MAX
#define mod 998244353
#define faster ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define FOR for(int i=1;i<=n;i++)
#define mid (start+end)/2
#define lim 10005
#define fi first
#define se second
int32_t main(){
faster
int n;cin>>n;
string s;cin>>s;
int q;cin>>q;
while(q--){
vector<int> v(n,0);
int top=0;
int l,r;cin>>l>>r;
l--;r--;
for(int i=l;i<r;i++){
if(s[i]=='C')top++;
else{
top--;
if(top<0){
v[i]=1;
top++;
}
}
}
top=0;
for(int i=r;i>=l;i--){
//cout<<top<<endl;
if(s[i]=='C')top++;
else if(v[i]==1)continue;
else{
top--;
if(top<0){
top++;
v[i]=1;
}
}
}
top=0;
for(int i=l;i<=r;i++){
top+=v[i];
//cout<<v[i]<<endl;
}
cout<<top<<'\n';
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
344 KB |
Output is correct |
2 |
Correct |
5 ms |
348 KB |
Output is correct |
3 |
Correct |
4 ms |
348 KB |
Output is correct |
4 |
Correct |
4 ms |
488 KB |
Output is correct |
5 |
Correct |
3 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
344 KB |
Output is correct |
2 |
Correct |
5 ms |
348 KB |
Output is correct |
3 |
Correct |
4 ms |
348 KB |
Output is correct |
4 |
Correct |
4 ms |
488 KB |
Output is correct |
5 |
Correct |
3 ms |
348 KB |
Output is correct |
6 |
Execution timed out |
3062 ms |
1572 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
344 KB |
Output is correct |
2 |
Correct |
5 ms |
348 KB |
Output is correct |
3 |
Correct |
4 ms |
348 KB |
Output is correct |
4 |
Correct |
4 ms |
488 KB |
Output is correct |
5 |
Correct |
3 ms |
348 KB |
Output is correct |
6 |
Execution timed out |
3062 ms |
1572 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |