This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 INT_MAX;
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-1] = 0, update(N+i-1);
}
for (int i = 1; i <= n; 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 |
---|
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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |