#include using namespace std; const int MAXN = 2e5 + 5, MAXK = 20; struct SegTree { int ans, n, m, len, pre[20], suf[20], lp[20], lq[20]; } tr[MAXN * 4], I; int T, n, k, a[MAXN]; void init(SegTree &u) { u = I; } SegTree Merge(SegTree l, SegTree r) { SegTree ret; init(ret); ret.ans = min(l.ans, r.ans); ret.n = l.n, ret.m = r.m; ret.len = l.len + r.len; for (int i = 1; i <= l.n; i++) { ret.pre[i] = l.pre[i], ret.lp[i] = l.lp[i]; } for (int i = 1; i <= r.n; i++) { if ((ret.pre[ret.n] | r.pre[i]) != ret.pre[ret.n]) { ret.pre[ret.n + 1] = (ret.pre[ret.n] | r.pre[i]); ret.lp[++ret.n] = l.len + r.lp[i]; } } for (int i = 1; i <= r.m; i++) { ret.suf[i] = r.suf[i], ret.lq[i] = r.lq[i]; } for (int i = 1; i <= l.m; i++) { if ((ret.suf[ret.m] | l.suf[i]) != ret.suf[ret.m]) { ret.suf[ret.m + 1] = (ret.suf[ret.m] | l.suf[i]); ret.lq[++ret.m] = r.len + l.lq[i]; } } for (int i = 1, j = r.n; i <= l.m; i++) { for (; j && (l.suf[i] | r.pre[j]) != (1 << k) - 1; j--); if (j) ret.ans = min(ret.ans, l.lq[i] + r.lp[j]); } return ret; } void bulid(int i, int l, int r) { if (l == r) { init(tr[i]), tr[i].len = 1; return ; } int mid = (l + r) >> 1; bulid(i * 2, l, mid), bulid(i * 2 + 1, mid + 1, r); } void modify(int i, int l, int r, int x, int v) { if (l == r) { tr[i].pre[1] = tr[i].suf[1] = v; tr[i].n = tr[i].m = tr[i].lp[1] = tr[i].lq[1] = 1; tr[i].ans = (v != (1 << k) - 1) * (n + 9) + 1; //cout << tr[i].ans << ' '; return ; } int mid = (l + r) >> 1; x <= mid ? modify(i * 2, l, mid, x, v) : modify(i * 2 + 1, mid + 1, r, x, v); tr[i] = Merge(tr[i * 2], tr[i * 2 + 1]); } SegTree query(int i, int l, int r, int ql, int qr) { if (l > qr || r < ql) return I; if (ql <= l && r <= qr) return tr[i]; int mid = (l + r) >> 1; return Merge(query(i * 2, l, mid, ql, qr), query(i * 2 + 1, mid + 1, r, ql, qr)); } int main() { ios::sync_with_stdio(0), cin.tie(0); I = {n + 10, 0, 0, 0}; for (int j = 0; j < 20; j++) { I.pre[j] = I.suf[j] = I.lp[j] = I.lq[j] = 0; } cin >> n >> k, bulid(1, 1, n); for (int i = 1; i <= n; i++) { cin >> a[i], modify(1, 1, n, i, a[i]); } //cout << tr[2].ans << '\n'; cin >> T; for (int op, u, v, l, r; T--; ) { cin >> op; if (op == 1) { cin >> u >> v; modify(1, 1, n, u, v); } else { cin >> l >> r; int ans = query(1, 1, n, l, r).ans; cout << (ans <= n ? ans : -1) << '\n'; } } return 0; }