#include using namespace std; using pir = pair; const int N = 2e5 + 5; const int M = 17; int n, k, q, a[N]; struct node{ int ans, maxx[M], minx[M]; void clean(){ ans = N; for(int i = 0; i < k; i++) maxx[i] = -N; for(int i = 0; i < k; i++) minx[i] = N; } }tr[4 * N]; node mymerge(int l, int mid, int r, const node &tl, const node &tr){ node m; m.clean(); m.ans = min(tl.ans, tr.ans); for(int i = 0; i < k; i++) m.maxx[i] = max(tl.maxx[i], tr.maxx[i]); for(int i = 0; i < k; i++) m.minx[i] = min(tl.minx[i], tr.minx[i]); if(m.ans == 1) return m; vector v; for(int i = 0; i < k; i++){ if(tl.maxx[i] != -N) v.push_back(tl.maxx[i]); if(tl.minx[i] != N) v.push_back(tl.minx[i]); if(tr.maxx[i] != -N) v.push_back(tr.maxx[i]); if(tr.minx[i] != N) v.push_back(tr.minx[i]); } sort(v.begin(), v.end()); for(int i = 0; i < v.size(); i++){ int sum = 0; for(int j = i; j < v.size(); j++){ sum |= a[v[j]]; if(sum == (1 << k) - 1){ m.ans = min(m.ans, v[j] - v[i] + 1); break; } } } return m; } void build(int id, int l, int r){ if(l == r){ tr[id].clean(); if(a[l] == (1 << k) - 1) tr[id].ans = 1; for(int i = 0; i < k; i++){ if((a[l] >> i) & 1) tr[id].maxx[i] = l; } return ; } int mid = (l + r) >> 1; build((id << 1), l, mid), build(((id << 1) | 1), mid + 1, r); tr[id] = mymerge(l, mid, r, tr[id << 1], tr[(id << 1) | 1]); } void change(int id, int l, int r, int x, int num){ if(l == r){ tr[id].clean(); if(num == (1 << k) - 1) tr[id].ans = 1; for(int i = 0; i < k; i++){ if((num >> i) & 1) tr[id].maxx[i] = x; } return ; } int mid = (l + r) >> 1; if(x <= mid) change((id << 1), l, mid, x, num); else change(((id << 1) | 1), mid + 1, r, x, num); tr[id] = mymerge(l, mid, r, tr[id << 1], tr[(id << 1) | 1]); } node sum; int nl, nr; void query(int id, int l, int r, int p, int q){ if(p <= l && q >= r){ if(nl == N){ sum = tr[id]; nl = min(nl, l), nr = max(nr, r); return ; } sum = mymerge(nl, nr, r, sum, tr[id]); nl = min(nl, l), nr = max(nr, r); return ; } if(r < p || l > q) return ; int mid = (l + r) >> 1; query((id << 1), l, mid, p, q), query(((id << 1) | 1), mid + 1, r, p, q); } long long getans(int l, int r){ nl = N, nr = 0, sum.clean(); query(1, 1, n, l, r); return sum.ans; } int main(){ ios::sync_with_stdio(0), cin.tie(0); cin >> n >> k; for(int i = 1; i <= n; i++) cin >> a[i]; build(1, 1, n); cin >> q; for(int i = 1, op; i <= q; i++){ cin >> op; if(op == 1){ int j, v; cin >> j >> v; a[j] = v; change(1, 1, n, j, v); } else{ int l, r; cin >> l >> r; int now = getans(l, r); if(now == N) cout << -1 << '\n'; else cout << now << '\n'; } } return 0; } /* 14 6 3 12 15 11 2 1 2 1 3 4 1 2 6 1 5 5 2 4 6 1 5 15 1 3 3 2 1 5 1 3 11 2 2 4 */