#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 5e5+23;
int a[N],n;
bool ode[N];
string s;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int q;
cin >> n;
cin >> s;
for(int i = 1; i <= n; i++){
a[i] = (s[i-1] == 'C' ? 1 : -1);
}
cin >> q;
while(q--){
int l,r;
cin >> l >> r;
int sol = 0,bal = 0;
for(int i = l; i <= r; i++){
ode[i] = 0;
}
for(int i = l; i <= r; i++){
bal += a[i];
if(bal < 0){
ode[i] = 1;
sol++;
bal++;
}
}
bal = 0;
for(int i = r; i >= l; i--){
if(ode[i]){
continue;
}
bal += a[i];
if(bal < 0){
sol++;
bal++;
}
}
cout << sol << endl;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
384 KB |
Output is correct |
2 |
Correct |
8 ms |
384 KB |
Output is correct |
3 |
Correct |
8 ms |
384 KB |
Output is correct |
4 |
Correct |
11 ms |
384 KB |
Output is correct |
5 |
Correct |
9 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
384 KB |
Output is correct |
2 |
Correct |
8 ms |
384 KB |
Output is correct |
3 |
Correct |
8 ms |
384 KB |
Output is correct |
4 |
Correct |
11 ms |
384 KB |
Output is correct |
5 |
Correct |
9 ms |
384 KB |
Output is correct |
6 |
Execution timed out |
3030 ms |
2284 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
384 KB |
Output is correct |
2 |
Correct |
8 ms |
384 KB |
Output is correct |
3 |
Correct |
8 ms |
384 KB |
Output is correct |
4 |
Correct |
11 ms |
384 KB |
Output is correct |
5 |
Correct |
9 ms |
384 KB |
Output is correct |
6 |
Execution timed out |
3030 ms |
2284 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |