#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
// #define int long long
#define endl '\n'
using namespace std;
using namespace __gnu_pbds;
using ordered_set = tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>;
signed main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int n,q;
cin>>n;
string s;
cin>>s;
vector<bool>v(n);
for(int i=0;i<n;i++)v[i]=(s[i]=='C');
vector<bool>V(n);
cin>>q;
while(q--){
int l,r;
cin>>l>>r;
l--;r--;
int cur=0,ans=0;
for(int i=l;i<=r;i++){
V[i]=0;
cur+=(v[i]?1:-1);
if(cur<0){
ans++;
V[i]=1;
cur=0;
}
}
cur=0;
for(int i=r;i>=l;i--){
if(V[i])continue;
cur+=(v[i]?1:-1);
if(cur<0){
ans++;
V[i]=1;
cur=0;
}
}
cout<<ans<<endl;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
328 KB |
Output is correct |
2 |
Correct |
10 ms |
352 KB |
Output is correct |
3 |
Correct |
9 ms |
340 KB |
Output is correct |
4 |
Correct |
7 ms |
336 KB |
Output is correct |
5 |
Correct |
6 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
328 KB |
Output is correct |
2 |
Correct |
10 ms |
352 KB |
Output is correct |
3 |
Correct |
9 ms |
340 KB |
Output is correct |
4 |
Correct |
7 ms |
336 KB |
Output is correct |
5 |
Correct |
6 ms |
340 KB |
Output is correct |
6 |
Execution timed out |
3063 ms |
780 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
328 KB |
Output is correct |
2 |
Correct |
10 ms |
352 KB |
Output is correct |
3 |
Correct |
9 ms |
340 KB |
Output is correct |
4 |
Correct |
7 ms |
336 KB |
Output is correct |
5 |
Correct |
6 ms |
340 KB |
Output is correct |
6 |
Execution timed out |
3063 ms |
780 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |