#include using namespace std; using pir = pair; const int N = 2e5 + 5; const int M = 17; int n, k, q, a[N]; struct segment_tree{ pir tr[4 * N]; pir tmerge(pir a, pir b){ return {min(a.first, b.first), max(a.second, b.second)}; } void build(int id, int l, int r){ tr[id] = {N, -N}; if(l == r) return ; int mid = (l + r) >> 1; build((id << 1), l, mid), build(((id << 1) | 1), mid + 1, r); tr[id] = tmerge(tr[id << 1], tr[(id << 1) | 1]); } void change(int id, int l, int r, int x, int num){ if(l == r){ if(num == N){ tr[id] = {N, -N}; return ; } tr[id] = {num, num}; 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] = tmerge(tr[id << 1], tr[(id << 1) | 1]); } pir query(int id, int l, int r, int p, int q){ if(p <= l && q >= r) return tr[id]; if(r < p || l > q) return {N, -N}; int mid = (l + r) >> 1; return tmerge(query((id << 1), l, mid, p, q), query(((id << 1) | 1), mid + 1, r, p, q)); } int Find_beter(int id, int l, int r, int p, int q){ if(p <= l && q >= r){ if(l == r){ return (tr[id].first < N ? l : N); } if(tr[id].first >= N) return N; int mid = (l + r) >> 1; if(tr[id << 1].first < N) return Find_beter((id << 1), l, mid, p, q); return Find_beter(((id << 1) | 1), mid + 1, r, p, q); } if(l == r) return N; if(l > q || r < p) return N; int mid = (l + r) >> 1; return min(Find_beter((id << 1), l, mid, p, q), Find_beter(((id << 1) | 1), mid + 1, r, p, q)); } }t[M]; void myerase(int x, int id){ for(int i = 0; i < k; i++){ if((x >> i) & 1) t[i].change(1, 1, n, id, N); } } void myinsert(int x, int id){ for(int i = 0; i < k; i++){ if((x >> i) & 1) t[i].change(1, 1, n, id, id); } } bool check(int l, int r){ for(int j = 0; j < k; j++){ pir q = t[j].query(1, 1, n, l, r); if(q.first == N || q.second == -N){ return 0; } } return 1; } int Find(int x){ int maxx = 0; for(int i = 0; i < k; i++){ maxx = max(maxx, t[i].Find_beter(1, 1, n, x, n)); if(maxx == n + 1) return n + 1; } return maxx; } struct node{ int ans, maxx[M]; void clean(){ ans = N; for(int i = 0; i < k; i++) maxx[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]); if(m.ans == 1) return m; for(int i = 0; i < k; i++){ if(tl.maxx[i] == -N) continue; int hb = Find(tl.maxx[i]); if(hb > r) continue; m.ans = min(m.ans, hb - tl.maxx[i] + 1); } 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 = 0; i < k; i++) t[i].build(1, 1, n); for(int i = 1; i <= n; i++) cin >> a[i]; for(int i = 1; i <= n; i++) myinsert(a[i], 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; myerase(a[j], j); myinsert(v, j); a[j] = v; change(1, 1, n, j, v); } else{ int l, r; cin >> l >> r; if(!check(l, r)){ cout << -1 << '\n'; continue; } cout << getans(l, r) << '\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 */