#include<bits/stdc++.h>
using namespace std;
const int N = 2e6+7;
int n,q;
string s;
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin>>n>>s>>q;
while(q--) {
int l,r;
cin>>l>>r; l--; r--;
string t = s;
int cnt1 = 0, cnt2 = 0, res = 0;
vector<bool> ok(n+1,0);
for(int i=l;i<=r;i++) {
if(t[i] == 'C') cnt1++; else cnt1--;
if(cnt1 < 0) {
t[i] = 'C';
ok[i] = 1;
res++;
cnt1++;
}
}
//for(int i=0;i<n;i++) cout<<t[i]<<" "; cout<<cnt1; cout<<'\n';
for(int i=r;i>=l;i--) {
if(ok[i]==1) continue;
if(t[i] == 'C') cnt2++; else cnt2--;
if(cnt2 < 0) {
t[i] = 'C';
res++;
cnt2++;
}
}
cout<<res<<'\n';
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
212 KB |
Output is correct |
2 |
Correct |
7 ms |
340 KB |
Output is correct |
3 |
Correct |
6 ms |
352 KB |
Output is correct |
4 |
Correct |
7 ms |
336 KB |
Output is correct |
5 |
Correct |
5 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
212 KB |
Output is correct |
2 |
Correct |
7 ms |
340 KB |
Output is correct |
3 |
Correct |
6 ms |
352 KB |
Output is correct |
4 |
Correct |
7 ms |
336 KB |
Output is correct |
5 |
Correct |
5 ms |
340 KB |
Output is correct |
6 |
Execution timed out |
3059 ms |
1144 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
212 KB |
Output is correct |
2 |
Correct |
7 ms |
340 KB |
Output is correct |
3 |
Correct |
6 ms |
352 KB |
Output is correct |
4 |
Correct |
7 ms |
336 KB |
Output is correct |
5 |
Correct |
5 ms |
340 KB |
Output is correct |
6 |
Execution timed out |
3059 ms |
1144 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |