#include using namespace std; const int N = 2e5 + 5; struct Node{ int l, r, sum, minx; vector>q, p; }t[N * 4]; int l, r, n, k, x, opt, q, a[N]; Node AND(Node a, Node b){ Node c; c.minx = min(a.minx, b.minx); c.sum = a.sum | b.sum; for(auto [v, len1] : a.q){ for(auto [u, len2] : b.p){ if((u | v) == (1 << k) - 1){ c.minx = min(c.minx, len1 + len2); } } } c.q.clear(), c.p.clear(); for(auto [v, len1] : a.p){ //cout << v << ' ' << len1 << '\n'; c.p.push_back({v, len1}); } for(auto [v, len2] : b.q){ //cout << v << ' ' << len2 << '\n'; c.q.push_back({v, len2}); } for(auto [v, len1] : a.q){ if(!c.q.size() || c.q.back().first != (v | b.sum)){ c.q.push_back({v | b.sum, len1 + b.r - b.l + 1}); } } for(auto [v, len2] : b.p){ if(!c.p.size() || c.p.back().first != (v | a.sum)){ c.p.push_back({v | a.sum, len2 + a.r - a.l + 1}); } } return c; } void renew(int p){ auto l = t[p].l; auto r = t[p].r; t[p] = AND(t[p * 2], t[p * 2 + 1]); t[p].l = l, t[p].r = r; } void build(int p, int l, int r){ t[p].l = l, t[p].r = r, t[p].minx = 1e9; if(l == r)return; int mid = (l + r) >> 1; build(p * 2, l, mid), build(p * 2 + 1, mid + 1, r); } void updata(int p, int l, int x){ //cout << p << ' ' << t[p].l << ' ' << t[p].r <<' ' << l << '\n'; if(t[p].l == t[p].r){ t[p].minx = 1e9; t[p].q.clear(), t[p].p.clear(); t[p].sum = x; if(x == (1 << k) - 1){ t[p].minx = 1; } t[p].p.push_back({x, 1}); t[p].q.push_back({x, 1}); return; } int mid = (t[p].l + t[p].r) >> 1; if(l <= mid)updata(p * 2, l, x); if(l > mid)updata(p * 2 + 1, l, x); renew(p); } Node getmin(int p, int l, int r){ //cout << p << ' ' << t[p].l << ' ' << t[p].r << ' ' << t[p].minx << '\n'; if(l <= t[p].l && r >= t[p].r){ return t[p]; } int mid = (t[p].l + t[p].r) >> 1; if(l <= mid){ if(r > mid){ return AND(getmin(p * 2, l, r), getmin(p * 2 + 1, l, r)); } return getmin(p * 2, l, r); } return getmin(p * 2 + 1, l, r); } int main(){ ios::sync_with_stdio(0), cin.tie(0); cin >> n >> k; build(1, 1, n); for(int i = 1; i <= n; ++i){ cin >> a[i]; updata(1, i, a[i]); } cin >> q; while(q--){ cin >> opt; if(opt == 1){ cin >> l >> x; updata(1, l, x); } else{ cin >> l >> r; auto ppq = getmin(1, l, r); cout << (ppq.minx == 1e9 ? -1 : ppq.minx) << '\n'; } } return 0; }