#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 7;
const int maxN = 1e5 + 7;
int n, m;
int a[maxN];
int leaf[4 * maxN]; // Lưu chỉ số của nút lá tương ứng với phần tử ở vị trí i trong dãy số
multiset <int> st[4 * maxN];
void build(int id, int l, int r) {
if (l == r) {
leaf[l] = id;
st[id].insert(a[l]);
return;
}
int mid = l + r >> 1;
build(2 * id, l, mid);
build(2 * id + 1, mid + 1, r);
st[id] = st[2 * id + 1];
for (auto x : st[2 * id]) st[id].insert(x);
}
void update(int i, int val){
int id = leaf[i];
int old = *st[id].begin();
while (id) {
st[id].erase(st[id].find(old));
st[id].insert(val);
id /= 2;
}
}
int get(int id, int l, int r, int u, int v, int k) {
if (l > v || r < u) return inf;
if (l >= u && r <= v) {
auto it = st[id].lower_bound(k);
if (it == st[id].end()) return inf;
return *it;
}
int mid = l + r >> 1;
int get1 = get(2 * id, l, mid, u, v, k);
int get2 = get(2 * id + 1, mid + 1, r, u, v, k);
return min(get1, get2);
}
int main() {
cin >> n >> m;
for (int i = 1; i <= n; ++i) cin >> a[i];
build(1, 1, n);
while (m--){
int type, l, r, k;
cin >> type;
if (type == 1) {
cin >> l >> k;
update(l, k);
}
else {
cin >> l >> r >> k;
int ans = get(1, 1, n, l, r, k);
cout << ((ans == inf) ? -1 : ans) << '\n';
}
}
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiAKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKIApjb25zdCBpbnQgaW5mICA9IDFlOSArIDc7CmNvbnN0IGludCBtYXhOID0gMWU1ICsgNzsKIAppbnQgbiwgbTsKaW50IGFbbWF4Tl07CmludCBsZWFmWzQgKiBtYXhOXTsgLy8gTMawdSBjaOG7iSBz4buRIGPhu6dhIG7DunQgbMOhIHTGsMahbmcg4bupbmcgduG7m2kgcGjhuqduIHThu60g4bufIHbhu4sgdHLDrSBpIHRyb25nIGTDo3kgc+G7kQptdWx0aXNldCA8aW50PiBzdFs0ICogbWF4Tl07CiAKdm9pZCBidWlsZChpbnQgaWQsIGludCBsLCBpbnQgcikgewogICAgaWYgKGwgPT0gcikgewogICAgICAgIGxlYWZbbF0gPSBpZDsKICAgICAgICBzdFtpZF0uaW5zZXJ0KGFbbF0pOwogICAgICAgIHJldHVybjsKICAgIH0KICAgIGludCBtaWQgPSBsICsgciA+PiAxOwogICAgYnVpbGQoMiAqIGlkLCBsLCBtaWQpOwogICAgYnVpbGQoMiAqIGlkICsgMSwgbWlkICsgMSwgcik7CiAgICAKICAgIHN0W2lkXSA9IHN0WzIgKiBpZCArIDFdOwogICAgZm9yIChhdXRvIHggOiBzdFsyICogaWRdKSBzdFtpZF0uaW5zZXJ0KHgpOwp9Cgp2b2lkIHVwZGF0ZShpbnQgaSwgaW50IHZhbCl7CiAgICBpbnQgaWQgID0gbGVhZltpXTsgCiAgICBpbnQgb2xkID0gKnN0W2lkXS5iZWdpbigpOwogICAgd2hpbGUgKGlkKSB7CiAgICAgICAgc3RbaWRdLmVyYXNlKHN0W2lkXS5maW5kKG9sZCkpOwogICAgICAgIHN0W2lkXS5pbnNlcnQodmFsKTsKICAgICAgICBpZCAvPSAyOwogICAgfQp9CiAKaW50IGdldChpbnQgaWQsIGludCBsLCBpbnQgciwgaW50IHUsIGludCB2LCBpbnQgaykgewogICAgaWYgKGwgPiAgdiB8fCByIDwgIHUpIHJldHVybiBpbmY7IAogICAgaWYgKGwgPj0gdSAmJiByIDw9IHYpIHsKICAgICAgICBhdXRvIGl0ID0gc3RbaWRdLmxvd2VyX2JvdW5kKGspOwogICAgICAgIGlmIChpdCA9PSBzdFtpZF0uZW5kKCkpIHJldHVybiBpbmY7CiAgICAgICAgcmV0dXJuICppdDsKICAgIH0KCiAgICBpbnQgbWlkID0gbCArIHIgPj4gMTsKICAgIGludCBnZXQxID0gZ2V0KDIgKiBpZCwgbCwgbWlkLCB1LCB2LCBrKTsKICAgIGludCBnZXQyID0gZ2V0KDIgKiBpZCArIDEsIG1pZCArIDEsIHIsIHUsIHYsIGspOwogICAgcmV0dXJuIG1pbihnZXQxLCBnZXQyKTsKfQoKaW50IG1haW4oKSB7CiAgICBjaW4gPj4gbiA+PiBtOwogICAgZm9yIChpbnQgaSA9IDE7IGkgPD0gbjsgKytpKSBjaW4gPj4gYVtpXTsKICAgIGJ1aWxkKDEsIDEsIG4pOwoKICAgIHdoaWxlIChtLS0pewogICAgICAgIGludCB0eXBlLCBsLCByLCBrOwogICAgICAgIGNpbiA+PiB0eXBlOwogICAgICAgIGlmICh0eXBlID09IDEpIHsKICAgICAgICAgICAgY2luID4+IGwgPj4gazsKICAgICAgICAgICAgdXBkYXRlKGwsIGspOwogICAgICAgIH0KICAgICAgICBlbHNlIHsKICAgICAgICAgICAgY2luID4+IGwgPj4gciA+PiBrOwogICAgICAgICAgICBpbnQgYW5zID0gZ2V0KDEsIDEsIG4sIGwsIHIsIGspOwogICAgICAgICAgICBjb3V0IDw8ICgoYW5zID09IGluZikgPyAtMSA6IGFucykgPDwgJ1xuJzsKICAgICAgICB9CiAgICB9Cn0K