#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N = 3e5 + 5;
struct segtree{
int t[4*N] = {0};
int query(int v, int tl, int tr, int l, int r) {
if(tl > r || tr < l) {
return 0;
}
if(tl >= l && tr <= r) {
return t[v];
}
int tm = (tl + tr) / 2;
return max(query(v * 2, tl, tm, l, r), query(v * 2 + 1, tm + 1, tr, l, r));
}
void update(int v, int tl, int tr, int index, int value) {
if(tl == tr) {
t[v] = value;
}
else {
int tm = (tl + tr) / 2;
if(index <= tm) {
update(v * 2, tl, tm, index, value);
}
else {
update(v * 2 + 1, tm + 1, tr, index, value);
}
t[v] = max(t[v * 2], t[v * 2 + 1]);
}
}
}seg;
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, q;
cin >> n >> q;
vector<int> a(n + 1);
for(int i = 1; i <= n; i++) {
char x;
cin >> x;
if(x == '1') {
a[i] = 1;
}
else {
a[i] = 0;
}
}
vector<int> op(q + 1, - 1);
for(int i = 1; i <= n; i++) {
if(a[i]) {
seg.update(1, 1, n, i, 0);
}
else {
seg.update(1, 1, n, i, N);
}
}
for(int i = 1; i <= q; i++) {
string type;
cin >> type;
if(type == "query") {
int l, r;
cin >> l >> r;
r -= 1;
cout << max(0LL, i - seg.query(1, 1, n, l, r)) << "\n";
}
else {
int index;
cin >> index;
seg.update(1, 1, n, index, i);
}
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |