This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define PB push_back
#define i2 array<int,2>
#define sz(x) ((int)x.size())
using namespace std;
typedef long long ll;
const int N = 100100;
const int oo = 2e9;
int n, k, a[N];
ll ALL;
struct seg{
    ll vls;
    int ans;
    vector<int> pref, suf;
    seg(): vls(0), ans(oo), pref(0), suf(0) {}
    void clear(){
        suf.clear();
        pref.clear();
        ans = oo;
        vls = 0;
    }
};
seg st[4 * N];
seg combine(seg &lf, seg &rt){
    seg res;
    res.clear();
    res.ans = min(lf.ans, rt.ans);
    res.vls = (lf.vls | rt.vls);
    if (res.vls == ALL){
        // recalc answer
        int ptr = sz(rt.pref) - 1;
        ll le = 0;
        for (int pos : lf.suf){
            le |= (1ll << a[pos]);
            if ((le | rt.vls) == ALL){
                while (ptr > 0 && (le & (1ll << a[rt.pref[ptr]]))){
                    ptr--;
                }
                res.ans = min(res.ans, rt.pref[ptr] - pos + 1);
            }
        }
    }
    res.pref = lf.pref;
    res.suf = rt.suf;
    for (int pos : rt.pref)
        if (!(lf.vls & (1ll << a[pos])))
            res.pref.PB(pos);
    for (int pos : lf.suf)
        if (!(rt.vls & (1ll << a[pos])))
            res.suf.PB(pos);
    return res;
}
void build(int v, int l, int r){
    if (l == r){
        st[v].clear();
        st[v].vls = (1ll << a[l]);
        st[v].pref.PB(l);
        st[v].suf.PB(l);
        return;
    }
    int md = (l + r) >> 1;
    build(v + v, l, md);
    build(v + v + 1, md + 1, r);
    st[v] = combine(st[v + v], st[v + v + 1]);
}
void update(int v, int l, int r, int ps){
    if (l == r){
        st[v].clear();
        st[v].vls = (1ll << a[l]);
        st[v].pref.PB(l);
        st[v].suf.PB(l);
        return;
    }
    int md = (l + r) >> 1;
    if (ps <= md)
        update(v + v, l, md, ps);
    else update(v + v + 1, md + 1, r, ps);
    st[v] = combine(st[v + v], st[v + v + 1]);
}
int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
#ifdef _LOCAL
    freopen("in.txt","r",stdin);
#endif // _LOCAL
    int qq;
    cin >> n >> k >> qq;
    ALL = (1ll << (k + 1)) - 2ll;
    for (int i = 0; i < n; i++)
        cin >> a[i];
    build(1, 0, n - 1);
    for (; qq; qq--){
        int tp; cin >> tp;
        if (tp == 1){
            int ps, vl; cin >> ps >> vl;
            ps--;
            a[ps] = vl;
            update(1, 0, n - 1, ps);
        } else {
            if (k == 1)
                cout << "1\n";
            else cout << (st[1].ans == oo ? -1 : st[1].ans) << '\n';
        }
    }
    return 0;
}
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |