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