#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
typedef long long ll;
typedef pair<ll,ll> pi;
typedef vector<ll> vi;
typedef long double ld;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<ll>::iterator sit;
typedef map<ll,ll>::iterator mit;
typedef pair<int,pair<int,int> > tri;
int n, q;
string s;
int used[500050];
void calcpre(int l, int r){
int now = 0;
for(int i = l; i <= r; i++){
if(used[i]) continue;
if(s[i] == 'C') now--;
else now++;
if(now > 0){
used[i] = 1;
now--;
}
}
}
void calcsuf(int l, int r){
int now = 0;
for(int i = r; i >= l; i--){
if(used[i]) continue;
if(s[i] == 'C') now--;
else now++;
if(now > 0){
used[i] = 1;
now--;
}
}
}
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> n >> s >> q;
while(q--){
int l, r;
cin >> l >> r;
l--; r--;
calcpre(l,r); calcsuf(l,r);
int ans = 0;
for(int i = l; i <= r; i++) {
if(used[i]) ans++;
used[i] = 0;
}
cout << ans << endl;
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
376 KB |
Output is correct |
2 |
Correct |
17 ms |
564 KB |
Output is correct |
3 |
Correct |
13 ms |
564 KB |
Output is correct |
4 |
Correct |
12 ms |
564 KB |
Output is correct |
5 |
Correct |
13 ms |
564 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
376 KB |
Output is correct |
2 |
Correct |
17 ms |
564 KB |
Output is correct |
3 |
Correct |
13 ms |
564 KB |
Output is correct |
4 |
Correct |
12 ms |
564 KB |
Output is correct |
5 |
Correct |
13 ms |
564 KB |
Output is correct |
6 |
Execution timed out |
3032 ms |
1300 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
376 KB |
Output is correct |
2 |
Correct |
17 ms |
564 KB |
Output is correct |
3 |
Correct |
13 ms |
564 KB |
Output is correct |
4 |
Correct |
12 ms |
564 KB |
Output is correct |
5 |
Correct |
13 ms |
564 KB |
Output is correct |
6 |
Execution timed out |
3032 ms |
1300 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |