#include <iostream>
#define rep(i, a, b) for (auto i = (a); i < (b); ++i)
#define f first
#define s second
using namespace std;
using ll = int64_t;
const int N = 1 << 17, K = 51, inf = 1e9;
int U, sz;
struct S {
int len, ans;
pair<ll, int> pref[K], suff[K];
S() : len{0}, ans{inf} { }
S(int p, int v) : len{1}, ans{U != 1 ? inf : 1} {
pref[0] = suff[0] = {1ll << v, p};
}
S(const S &l, const S &r) : ans{min(l.ans, r.ans)} {
len = 0;
rep(i, 0, l.len) pref[len++] = l.pref[i];
rep(i, 0, r.len)
if (len) {
pref[len] = r.pref[i];
pref[len].f |= pref[len - 1].f;
if (pref[len].f != pref[len - 1].f) ++len;
} else pref[len++] = r.pref[i];
len = 0;
rep(i, 0, r.len) suff[len++] = r.suff[i];
rep(i, 0, l.len)
if (len) {
suff[len] = l.suff[i];
suff[len].f |= suff[len - 1].f;
if (suff[len].f != suff[len - 1].f) ++len;
} else suff[len++] = l.suff[i];
for (int s = l.len, p = 0; s--; ) {
while (p < r.len && (l.suff[s].f | r.pref[p].f) != U) ++p;
if (p < r.len && (l.suff[s].f | r.pref[p].f) == U)
ans = min(ans, r.pref[p].s - l.suff[s].s + 1);
}
}
} t[N << 1];
int query() { return t[1].ans; }
void update(int p, int v) {
p += sz;
for (t[p] = {p - sz, v}; p >>= 1; )
t[p] = {t[p << 1], t[p << 1|1]};
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, k, q; cin >> n >> k >> q; U = (1ll << k) - 1;
for (sz = 1; sz < n; sz <<= 1);
rep(i, 0, n) { int v; cin >> v; --v; update(i, v); }
while (q--) {
short t; cin >> t; --t;
if (t) cout << (query() != inf ? query() : -1) << '\n';
else {
int p, v; cin >> p >> v; --p; --v;
update(p, v);
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
252 ms |
420984 KB |
Output is correct |
2 |
Correct |
247 ms |
420984 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
269 ms |
421036 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
294 ms |
421036 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
770 ms |
420984 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1239 ms |
421256 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1331 ms |
421496 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1687 ms |
421500 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1624 ms |
421496 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2270 ms |
421444 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2290 ms |
421408 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |