#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(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(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, tr[id].minx[i] = l; } return ; } int mid = (l + r) >> 1; build((id << 1), l, mid), build(((id << 1) | 1), mid + 1, r); tr[id] = mymerge(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, tr[id].minx[i] = l; } 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(tr[id << 1], tr[(id << 1) | 1]); } node sum; void query(int id, int l, int r, int p, int q){ if(p <= l && q >= r){ if(sum.ans == N){ sum = tr[id]; return ; } sum = mymerge(sum, tr[id]); 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){ 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; }