#include using namespace std; #define int long long const int N = 2e5 + 5, M = 17, INF = 1e18; int n, k, a[N], q; struct node { int ans, maxi[M], mini[M]; void clean() { ans = INF; for (int i = 0; i <= k; i++) { maxi[i] = -INF; mini[i] = INF; } } }tr[N * 4], CANT, tmp; node Merge(node l, node r) { node m; m.clean(); m.ans = min(l.ans, r.ans); vector v; for (int i = 0; i <= k; i++) { m.maxi[i] = max(l.maxi[i], r.maxi[i]); m.mini[i] = min(l.mini[i], r.mini[i]); if (l.maxi[i] != -INF) { v.push_back(l.maxi[i]); } if (r.mini[i] != INF) { v.push_back(r.mini[i]); } } if (m.ans == 1) { return m; } sort(v.begin(), v.end()); for (int i = 0; i < v.size(); i++) { int tot = 0; for (int j = i; j < v.size(); j++) { tot |= a[v[j]]; if (tot == ((1 << k) - 1)) { m.ans = min(m.ans, v[j] - v[i] + 1); break; } } } return m; } void build(int i, int l, int r) { if (l == r) { tr[i].clean(); if (a[l] == ((1 << k) - 1)) { tr[i].ans = 1; } for (int j = 0; j <= k; j++) { if ((a[l] & (1 << j))) { tr[i].maxi[j] = l, tr[i].mini[j] = l; } } return ; } int mid = (l + r) >> 1; build(i * 2, l, mid); build(i * 2 + 1, mid + 1, r); tr[i] = Merge(tr[i * 2], tr[i * 2 + 1]); } void change(int i, int l, int r, int p, int x) { if (l == r) { a[l] = x; tr[i].clean(); if (a[l] == ((1 << k) - 1)) { tr[i].ans = 1; } for (int j = 0; j <= k; j++) { if ((a[l] & (1 << j))) { tr[i].maxi[j] = l, tr[i].mini[j] = l; } } return ; } int mid = (l + r) >> 1; if (mid >= p) { change(i * 2, l, mid, p, x); } else change(i * 2 + 1, mid + 1, r, p, x); tr[i] = Merge(tr[i * 2], tr[i * 2 + 1]); } void query(int i, int l, int r, int x, int y) { if (l > y || r < x) { return ; } if (l >= x && r <= y) { tmp = Merge(tmp, tr[i]); return ; } int mid = (l + r) >> 1; query(i * 2, l, mid, x, y); query(i * 2 + 1, mid + 1, r, x, y); } signed main() { ios::sync_with_stdio(0); cin.tie(0); CANT.clean(); cin >> n >> k; for (int i = 1; i <= n; i++) { cin >> a[i]; } build(1, 1, n); cin >> q; while (q--) { int opt, x, y; cin >> opt >> x >> y; if (opt == 1) { change(1, 1, n, x, y); } else { tmp.clean(); query(1, 1, n, x, y); if (tmp.ans == INF) { cout << "-1\n"; } else cout << tmp.ans << "\n"; } } return 0; } /* 6 4 14 12 15 12 13 11 5 2 1 2 1 3 4 1 2 6 1 5 5 2 4 6 */