1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
| #include <cstdio> using namespace std; template <class Type> void read (Type &x) { char c; bool flag = false; while ((c = getchar()) < '0' || c > '9') c == '-' && (flag = true); x = c - '0'; while ((c = getchar()) >= '0' && c <= '9') x = (x << 1) + (x << 3) + c - '0'; flag && (x = ~x + 1); } template <class Type, class ...rest> void read (Type &x, rest &...y) { read(x), read(y...); } template <class Type> void write (Type x) { x < 0 && (putchar('-'), x = ~x + 1); x > 9 && (write(x / 10), 0); putchar('0' + x % 10); } const int N = 1e5 + 10; bool v[N]; int n, m, q, w[N]; struct Op { int op, l, r; } o[N]; struct Node { int l, r, tag, c; } tr[N << 2]; void pushup (int x) { tr[x].c = tr[x << 1].c + tr[x << 1 | 1].c; } void cover (int x, bool k) { tr[x].c = (tr[x].r - tr[x].l + 1) * k, tr[x].tag = k; } void pushdown (int x) { if (!~tr[x].tag) return; cover(x << 1, tr[x].tag), cover(x << 1 | 1, tr[x].tag); tr[x].tag = -1; } void build (int l = 1, int r = n, int x = 1) { tr[x].l = l, tr[x].r = r, tr[x].tag = -1; if (l == r) return void(tr[x].c = v[l]); int mid = l + r >> 1; build(l, mid, x << 1), build(mid + 1, r, x << 1 | 1); pushup(x); } void modify (int l, int r, bool k, int x = 1) { if (tr[x].l > r || l > tr[x].r) return; if (tr[x].l >= l && tr[x].r <= r) return cover(x, k); pushdown(x); int mid = tr[x].l + tr[x].r >> 1; modify(l, r, k, x << 1), modify(l, r, k, x << 1 | 1); pushup(x); } int query (int l, int r, int x = 1) { if (tr[x].l > r || l > tr[x].r) return 0; if (tr[x].l >= l && tr[x].r <= r) return tr[x].c; pushdown(x); int mid = tr[x].l + tr[x].r >> 1; return query(l, r, x << 1) + query(l, r, x << 1 | 1); } bool check (int k) { for (int i = 1; i <= n; ++i) v[i] = w[i] > k; build(); for (int i = 1; i <= m; ++i) { int c = query(o[i].l, o[i].r); if (o[i].op == 0) modify(o[i].l, o[i].r - c, 0), modify(o[i].r - c + 1, o[i].r, 1); else if (o[i].op == 1) modify(o[i].l, o[i].l + c - 1, 1), modify(o[i].l + c, o[i].r, 0); } return !query(q, q); } int main () { read(n, m); for (int i = 1; i <= n; ++i) read(w[i]); for (int i = 1; i <= m; ++i) read(o[i].op, o[i].l, o[i].r); read(q); int l = 1, r = n; while (l < r) { int mid = l + r >> 1; check(mid) ? r = mid : l = mid + 1; } write(l); return 0; }
|