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;
const int INF = 1e9;
struct SegTree {
int l, r, mid;
int val = INF;
SegTree *lc, *rc;
SegTree(int _l, int _r): l(_l), r(_r){
mid = (l + r) / 2;
if (l == r - 1) return;
lc = new SegTree(l, mid);
rc = new SegTree(mid, r);
}
void pull(){
val = max(lc->val, rc->val);
}
void update(int i, int u){
if (l == r - 1)
return void(val = u);
if (i < mid)
lc->update(i, u);
else
rc->update(i, u);
pull();
}
int query(int ll, int rr){
if (ll <= l && rr >= r)
return val;
int ret = -INF;
if (ll < mid)
ret = max(ret, lc->query(ll, rr));
if (mid < rr)
ret = max(ret, rc->query(ll, rr));
return ret;
}
};
int main(){
cin.tie(0)->sync_with_stdio(0);
int n, q; cin >> n >> q;
vector<bool> a(n);
for (int i = 0; i < n; i++){
char c; cin >> c;
a[i] = c - '0';
}
SegTree st(0, n);
for (int i = 0; i < n; i++)
if (a[i])
st.update(i, 0);
for (int qq = 1; qq <= q; qq++){
string ty; cin >> ty;
if (ty == "toggle"){
int i; cin >> i;
i--;
st.update(i, qq);
}else{
int l, r; cin >> l >> r;
l--, r--;
cout << max(0, qq - st.query(l, r)) << '\n';
}
}
return 0;
}
# | 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... |