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 <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <deque>
#include <map>
#include <set>
#include <complex>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <random>
#define ft first
#define sc second
#define pb push_back
#define len(v) (int)v.size()
#define int ll
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int inf = 1e9 + 100;
int N = (1 << 17);
vector<int> tree(2 * N, inf);
void upd(int v) {
if(v == 0)
return;
tree[v] = max(tree[v * 2], tree[v * 2 + 1]);
upd(v / 2);
}
int get(int v, int l, int r, int vl, int vr) {
if(r <= vl || vr <= l)
return 0;
if(vl <= l && r <= vr)
return tree[v];
int mid = (l + r) / 2;
return max(get(v * 2, l, mid, vl, vr), get(v * 2 + 1, mid, r, vl, vr));
}
signed main() {
#ifdef PC
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, q;
cin >> n >> q;
vector<int> ans(n, 0);
for (int i = 0; i < n; i++) {
char c;
cin >> c;
if(c == '1') {
tree[N + i] = i;
upd((N + i) / 2);
}
}
for (int i = 0; i < q; i++) {
string s;
cin >> s;
if(s == "toggle") {
int id;
cin >> id;
id--;
tree[N + id] = (i + 1);
upd((N + id) / 2);
continue;
}
int l, r;
cin >> l >> r;
l--, r--;
int st = get(1, 0, N, l, r);
if(st == inf) {
cout << 0 << '\n';
continue;
}
cout << (i + 1) - st << '\n';
}
}
# | 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... |