#include using namespace std; const int N = 2e5 + 10, M = 20, INF = 1e9; struct Node { int ans, pre[M], suf[M], sum, pre_p[M], suf_p[M], len; } tr[4 * N], Empty; int n, k, a[N], q; Node Merge(Node i, Node j) { Node ret = Empty; ret.ans = min(i.ans, j.ans); for (int p = 0; p < k; p++) { for (int q = 0; q < k; q++) { if (i.suf[p] >= 0 && j.pre[q] >= 0 && (i.suf[p] | j.pre[q]) == (1 << k) - 1) { ret.ans = min(ret.ans, i.suf_p[p] + j.pre_p[q]); } } } int t = 0; for (int p = 0; p < k; p++) { if (i.pre[p] >= 0) ret.pre[t++] = i.pre[p], ret.pre_p[t - 1] = i.pre_p[p]; else { for (int q = 0; q < k; q++) { if (j.pre[q] >= 0 && (i.sum | j.pre[q]) > ret.pre[t - 1]) { ret.pre[t++] = i.sum | j.pre[q]; ret.pre_p[t - 1] = i.len + j.pre_p[q]; } } } } t = 0; for (int p = 0; p < k; p++) { if (j.suf[p] >= 0) ret.suf[t++] = j.suf[p], ret.suf_p[t - 1] = j.suf_p[p]; else { for (int q = 0; q < k; q++) { if (i.suf[q] >= 0 && (j.sum | i.suf[q]) > ret.suf[t - 1]) { ret.suf[t++] = j.sum | i.suf[q]; ret.suf_p[t - 1] = j.len + i.suf_p[q]; } } } } ret.sum = i.sum | j.sum, ret.len = i.len + j.len; return ret; } Node build(int i, int l, int r) { if (l == r) { tr[i].ans = (a[l] == (1 << k) - 1 ? 1 : INF); tr[i].pre[0] = tr[i].suf[0] = tr[i].sum = a[l]; tr[i].pre_p[0] = tr[i].suf_p[0] = tr[i].len = 1; return tr[i]; } int mid = (l + r) >> 1; return tr[i] = Merge(build(i * 2, l, mid), build(i * 2 + 1, mid + 1, r)); } void modify(int i, int l, int r, int pos, int x) { if (l == r) { tr[i] = Empty; tr[i].ans = (x == (1 << k) - 1 ? 1 : INF); tr[i].pre[0] = tr[i].suf[0] = tr[i].sum = x; tr[i].pre_p[0] = tr[i].suf_p[0] = tr[i].len = 1; return ; } int mid = (l + r) >> 1; pos <= mid ? modify(i * 2, l, mid, pos, x) : modify(i * 2 + 1, mid + 1, r, pos, x); tr[i] = Merge(tr[i * 2], tr[i * 2 + 1]); } Node query(int i, int l, int r, int ql, int qr) { if (qr < l || ql > r) return Empty; 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); Empty.ans = INF, Empty.sum = Empty.len = 0; fill(Empty.pre, Empty.pre + 20, -1); fill(Empty.suf, Empty.suf + 20, -1); fill(Empty.pre_p, Empty.pre_p + 20, INF); fill(Empty.suf_p, Empty.suf_p + 20, INF); cin >> n >> k; for (int i = 1; i <= n; i++) cin >> a[i]; fill(tr + 1, tr + 4 * n + 1, Empty); cin >> q, build(1, 1, n); while (q--) { int op; cin >> op; if (op == 1) { int i, x; cin >> i >> x; modify(1, 1, n, i, x); } else { int l, r; cin >> l >> r; Node t = query(1, 1, n, l, r); cout << (t.ans == INF ? -1 : t.ans) << '\n'; } } return 0; }