#include #include #include using namespace std; template bool chmax(T &m, const T q) { return m < q ? (m = q, true) : false; } template bool chmin(T &m, const T q) { return m > q ? (m = q, true) : false; } #include constexpr int inf = 1 << 28; int K; int full; struct S { int len = 0; int ans = inf; vector> left_cs, right_cs; static S gen(int a) { return S{1, (a == full ? 1 : inf), {{1, a}}, {{1, a}}}; } static vector> merge(const vector> &v1, const vector> &v2, int len1) { auto ret = v1; int mask = v1.empty() ? 0 : v1.back().second; for (auto [k, v] : v2) { if (chmax(mask, mask | v)) ret.emplace_back(k + len1, mask); } return ret; } }; S op(S l, S r) { auto len = l.len + r.len; auto left_cs = S::merge(l.left_cs, r.left_cs, l.len); auto right_cs = S::merge(r.right_cs, l.right_cs, r.len); int ans = min(l.ans, r.ans); for (auto [k1, v1] : l.right_cs) { for (auto [k2, v2] : r.left_cs) { if ((v1 | v2) == full) { chmin(ans, k1 + k2); break; } } } return S{len, ans, move(left_cs), move(right_cs)}; } S e() { return S(); } int main() { cin.tie(nullptr), ios::sync_with_stdio(false); int N; cin >> N >> K; full = (1 << K) - 1; vector init; while (N--) { int a; cin >> a; init.emplace_back(S::gen(a)); } int Q; cin >> Q; atcoder::segtree seg(init); while (Q--) { int tp, l, r; cin >> tp >> l >> r; --l; if (tp == 1) { seg.set(l, S::gen(r)); } else { auto p = seg.prod(l, r).ans; cout << (p == inf ? -1 : p) << '\n'; } } }