#include using namespace std; using pir = pair; const int N = 2e5 + 5; const int M = 20; 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 mymerge(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; } 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]; mymerge(a[i], i); } cin >> q; for(int i = 1, op, l, r; i <= q; i++){ cin >> op >> l >> r; if(op == 1){ myerase(a[l], l); mymerge(r, l); a[l] = r; } else{ if(!check(l, r)) cout << -1 << '\n'; else{ int ans = r - l + 1; for(int j = 0; j < k; j++){ pir q = t[j].query(1, 1, n, l, r); int now = Find(q.first); if(now == n + 1) continue; ans = min(ans, now - q.first + 1); now = Find(q.second); ans = min(ans, now - q.second + 1); } cout << ans << '\n'; } } } return 0; }