#include #define _1 (__int128)1 using namespace std; using ll = long long; void FileIO (const string s) { freopen(string(s + ".in").c_str(), "r", stdin); freopen(string(s + ".out").c_str(), "w", stdout); } const int N = 2e5 + 10, K = 20, INF = 1e9; struct SegTree { int pre[K], suf[K], p[K], s[K], pc, sc, ans, len; } tr[N * 4], ans; int n, k, a[N], q, op, x, y; SegTree Merge (SegTree x, SegTree y) { if (!x.len) return y; if (!y.len) return x; SegTree ret; ret.pc = ret.sc = 0, ret.ans = min(x.ans, y.ans), ret.len = x.len + y.len; for (int i = 1; i <= x.pc; i++) ret.pre[++ret.pc] = x.pre[i], ret.p[ret.pc] = x.p[i]; for (int i = 1; i <= y.pc; i++) if ((y.pre[i] | ret.pre[ret.pc]) != ret.pre[ret.pc]) ret.pre[ret.pc + 1] = (y.pre[i] | ret.pre[ret.pc]), ret.p[ret.pc + 1] = y.p[i] + x.len, ret.pc++; for (int i = 1; i <= y.sc; i++) ret.suf[++ret.sc] = y.suf[i], ret.s[ret.sc] = y.s[i]; for (int i = 1; i <= x.sc; i++) if ((x.suf[i] | ret.suf[ret.sc]) != ret.suf[ret.sc]) ret.suf[ret.sc + 1] = (x.suf[i] | ret.suf[ret.sc]), ret.s[ret.sc + 1] = x.s[i] + y.len, ret.sc++; for (int i = 1; i <= x.sc; i++) for (int j = 1; j <= y.pc; j++) if ((x.suf[i] | y.pre[j]) == (1 << k) - 1) ret.ans = min(ret.ans, (x.s[i] + y.p[j])); return ret; } void pushup (int id) { tr[id] = Merge(tr[id * 2], tr[id * 2 + 1]); } void build (int id, int l, int r) { if (l == r) { tr[id].len = 1; tr[id].pc = tr[id].sc = 0, tr[id].ans = INF; tr[id].pre[++tr[id].pc] = a[l], tr[id].p[tr[id].pc] = 1; tr[id].suf[++tr[id].sc] = a[l], tr[id].s[tr[id].sc] = 1; if (a[l] == (1 << k) - 1) tr[id].ans = 1; return ; } int mid = (l + r) >> 1; build(id * 2, l, mid), build(id * 2 + 1, mid + 1, r); pushup(id); } void modify (int id, int l, int r, int x, int y) { if (l == r) { tr[id].pc = tr[id].sc = 0, tr[id].ans = INF; tr[id].pre[++tr[id].pc] = y, tr[id].p[tr[id].pc] = 1; tr[id].suf[++tr[id].sc] = y, tr[id].s[tr[id].sc] = 1; if (y == (1 << k) - 1) tr[id].ans = 1; return ; } int mid = (l + r) >> 1; if (mid >= x) modify(id * 2, l, mid, x, y); else modify(id * 2 + 1, mid + 1, r, x, y); pushup(id); } void Query (int id, int l, int r, int x, int y) { if (l >= x && r <= y) { ans = Merge(ans, tr[id]); return ; } if (l > y || r < x) return ; int mid = (l + r) >> 1; Query(id * 2, l, mid, x, y), Query(id * 2 + 1, mid + 1, r, x, y); } signed main () { ios::sync_with_stdio(0), cin.tie(0); // FileIO(""); cin >> n >> k; for (int i = 1; i <= n; i++) cin >> a[i]; build(1, 1, n); for (cin >> q; q--; ) { cin >> op >> x >> y; if (op == 1) modify(1, 1, n, x, y); else { ans.len = 0; Query(1, 1, n, x, y); cout << (ans.ans == INF ? -1 : ans.ans) << '\n'; } } return 0; } /* 3 2 1 2 3 3 2 1 3 1 2 1 2 1 2 */