int n, m; int a[N]; int root[N], tot; int ls[N * 25], rs[N * 25], val[N * 25];
voidbuild(int &u, int l, int r) { u = ++tot; if (l == r) val[u] = a[l]; else { int mid = l + r >> 1; build(ls[u], l, mid); build(rs[u], mid + 1, r); } }
voidmodify(int &u, int v, int l, int r, int p, int x) { u = ++tot; ls[u] = ls[v], rs[u] = rs[v], val[u] = val[v]; if (l == r) val[u] = x; else { int mid = l + r >> 1; if (p <= mid) modify(ls[u], ls[v], l, mid, p, x); elsemodify(rs[u], rs[v], mid + 1, r, p, x); } }
intquery(int u, int l, int r, int p) { if (l == r) return val[u]; int mid = l + r >> 1; if (p <= mid) returnquery(ls[u], l, mid, p); elsereturnquery(rs[u], mid + 1, r, p); }
intmain() { cin >> n >> m; for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
build(root[0], 1, n);
for (int i = 1; i <= m; i++) { int ver, st, p, x; scanf("%d%d%d", &ver, &st, &p); if (st == 1) { scanf("%d", &x); modify(root[i], root[ver], 1, n, p, x); } else { root[i] = root[ver]; printf("%d\n", query(root[i], 1, n, p)); } }
int n, m; int a[N], b[N]; int root[N], tot; int ls[N * 25], rs[N * 25], sum[N * 25];
voidmodify(int &u, int v, int l, int r, int p) { u = ++tot; ls[u] = ls[v], rs[u] = rs[v], sum[u] = sum[v] + 1; if (l == r) return; int mid = l + r >> 1; if (p <= mid) modify(ls[u], ls[v], l, mid, p); elsemodify(rs[u], rs[v], mid + 1, r, p); }
intquery(int u, int v, int l, int r, int k) { if (l == r) return l; int s = sum[ls[u]] - sum[ls[v]]; int mid = l + r >> 1; if (k <= s) returnquery(ls[u], ls[v], l, mid, k); elsereturnquery(rs[u], rs[v], mid + 1, r, k - s); }
intmain() { cin >> n >> m; for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i <= n; i++) b[i] = a[i]; sort(b + 1, b + 1 + n);
int bn = unique(b + 1, b + 1 + n) - b - 1; for (int i = 1; i <= n; i++) { int l = 1, r = bn; while (l < r) { int mid = l + r >> 1; if (b[mid] < a[i]) l = mid + 1; else r = mid; } modify(root[i], root[i - 1], 1, bn, l); }
while (m--) { int l, r, k; cin >> l >> r >> k; int p = query(root[r], root[l - 1], 1, bn, k); cout << b[p] << endl; }