#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, ALL, a[N];
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;
assert(k < 30);
ALL = (1 << (k + 1)) - 2;
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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
24 ms |
25856 KB |
Output is correct |
2 |
Correct |
24 ms |
25856 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
43 ms |
51320 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
44 ms |
51312 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
43 ms |
51320 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
43 ms |
51320 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
45 ms |
51320 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
44 ms |
51320 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
59 ms |
51456 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
49 ms |
51320 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
54 ms |
51320 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |