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 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
| #include<bits/stdc++.h> using namespace std;
typedef long long ll; typedef __int128 int128;
namespace FastIO { template<typename T> inline T read(T& x) { x = 0; int f = 1; char ch; while (!isdigit(ch = getchar())) if (ch == '-') f = -1; while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar(); x *= f; return x; } template<typename T, typename... Args> inline void read(T& x, Args &...x_) { read(x); read(x_...); return; } inline ll read() { ll x; read(x); return x; } }; using namespace FastIO;
const int N = 100010;
int n, m, q; int a[N]; struct Que { int op, l, r; }Q[N];
class SegTree { private : struct Node { int L, R; int sum, lazy; }node[N << 2]; public : void Add(int p, int v) { node[p].sum = (node[p].R - node[p].L + 1) * v; node[p].lazy = v; } void PushDown(int p) { if(node[p].lazy == -1) return ; Add(p << 1, node[p].lazy); Add(p << 1 | 1, node[p].lazy); node[p].lazy = -1; }
void Build(int p, int L, int R, int x) { node[p].L = L, node[p].R = R, node[p].lazy = -1; if(L == R) { node[p].sum = (a[L] >= x); return; } int mid = L + R >> 1; Build(p << 1, L, mid, x); Build(p << 1 | 1, mid + 1, R, x); node[p].sum = node[p << 1].sum + node[p << 1 | 1].sum; } void Modify(int p, int L, int R, int v) { if(L <= node[p].L && node[p].R <= R) { Add(p, v); return ; } PushDown(p); int mid = (node[p].L + node[p].R) >> 1; if(L <= mid) Modify(p << 1, L, R, v); if(R > mid) Modify(p << 1 | 1, L, R, v); node[p].sum = node[p << 1].sum + node[p << 1 | 1].sum; } int Query(int p, int L, int R) { if(L <= node[p].L && node[p].R <= R) { return node[p].sum; } PushDown(p); int mid = (node[p].L + node[p].R) >> 1; int ans = 0; if(L <= mid) ans += Query(p << 1, L, R); if(R > mid) ans += Query(p << 1 | 1, L, R); return ans; } };
SegTree tree;
void Input() { read(n, m); for(int i = 1; i <= n; i++) { read(a[i]); } for(int i = 1; i <= m; i++) { read(Q[i].op, Q[i].l, Q[i].r); } read(q); }
bool Check(int mid) { tree.Build(1, 1, n, mid); for(int i = 1; i <= m; i++) { int cnt1 = tree.Query(1, Q[i].l, Q[i].r); if(cnt1 == 0 || cnt1 == Q[i].r - Q[i].l + 1) continue; if(Q[i].op) { tree.Modify(1, Q[i].l, Q[i].l + cnt1 - 1, 1); tree.Modify(1, Q[i].l + cnt1, Q[i].r, 0); } else { tree.Modify(1, Q[i].l, Q[i].r - cnt1, 0); tree.Modify(1, Q[i].r - cnt1 + 1, Q[i].r, 1); } } return tree.Query(1, q, q); }
void Work() { int l = 1, r = n, best = -1; while(l <= r) { int mid = l + r >> 1; if(Check(mid)) { l = mid + 1; best = mid; } else { r = mid - 1; } } printf("%d", best); }
int main() { Input(); Work(); return 0; }
|