#include <bits/stdc++.h>
using namespace std;
const int N = 2e3 + 5;
int n, q, arr[N], arr2[N], l, r, sum;
char c;
int main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);
cin >> n;
for(int i = 1; i <= n; i++){
cin >> c;
arr[i] = (c == 'C' ? 1 : -1);
}
cin >> q;
while(q--){
cin >> l >> r;
copy(arr + l, arr + r + 1, arr2 + l);
sum = 0;
for(int i = l; i <= r; i++){
if(sum + arr2[i] < 0) arr2[i] = 0;
sum += arr2[i];
}
sum = 0;
for(int i = r; i >= 1; i--){
if(sum + arr2[i] < 0) arr2[i] = 0;
sum += arr2[i];
}
cout << count(arr2 + l, arr2 + r + 1, 0) << "\n";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
340 KB |
Output is correct |
2 |
Correct |
6 ms |
288 KB |
Output is correct |
3 |
Correct |
4 ms |
340 KB |
Output is correct |
4 |
Correct |
5 ms |
360 KB |
Output is correct |
5 |
Correct |
4 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
340 KB |
Output is correct |
2 |
Correct |
6 ms |
288 KB |
Output is correct |
3 |
Correct |
4 ms |
340 KB |
Output is correct |
4 |
Correct |
5 ms |
360 KB |
Output is correct |
5 |
Correct |
4 ms |
340 KB |
Output is correct |
6 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
340 KB |
Output is correct |
2 |
Correct |
6 ms |
288 KB |
Output is correct |
3 |
Correct |
4 ms |
340 KB |
Output is correct |
4 |
Correct |
5 ms |
360 KB |
Output is correct |
5 |
Correct |
4 ms |
340 KB |
Output is correct |
6 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |