#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
const signed M = 3e6, MOD = 998244353;
int N = 1 << 20;
int seg[M];
void update(int ind) {
while (ind /= 2) seg[ind] = max(seg[ind*2], seg[ind*2+1]);
}
int query(int L, int R, int l = 1, int r = N, int ind = 1) {
if (r < L || l > R) return 0;
if (L <= l && r <= R) return seg[ind];
return max(query(L, R, l, (l+r)/2, ind*2), query(L, R, (l+r)/2+1, r, ind*2+1));
}
signed main() {
cin.tie(0)->sync_with_stdio(0);
for (int &i:seg) i = INT_MAX;
int n, q;
cin >> n >> q;
string s;
cin >> s;
for (int i = 0; i < n; i++) {
if (s[i] == '1') seg[N+i] = 0, update(N+i);
}
for (int i = 1; i <= q; i++) {
string s;
cin >> s;
if (s == "query") {
int l, r;
cin >> l >> r;
cout << max(0ll, i-query(l, r)) << endl;
} else {
int x;
cin >> x;
seg[N+x-1] = i;
update(N+x-1);
}
}
return 0;
}
/*
5 7
11011
query 1 2
query 1 2
query 1 6
query 3 4
toggle 3
query 3 4
query 1 6
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
10 ms |
23764 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
103 ms |
24240 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
23764 KB |
Output is correct |
2 |
Correct |
11 ms |
23684 KB |
Output is correct |
3 |
Correct |
15 ms |
23820 KB |
Output is correct |
4 |
Incorrect |
13 ms |
23764 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
11 ms |
23752 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
10 ms |
23764 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |