#include <bits/stdc++.h>
#define rep(i, a, b) for (auto i = (a); i < (b); ++i)
#define f first
#define s second
using namespace std;
using ll = long long;
const int N = 1 << 17, K = 51, inf = 1e9;
template<class T> bool ckmin(T& a, const T& b) { return a > b ? a = b, 1 : 0; }
int U;
struct S {
int len, ans;
pair<ll, int> pref[K], suff[K];
S() : ans{inf}, len{0} { }
S(int p, int v) {
len = 1;
pref[0] = suff[0] = {1ll << v, p};
ans = inf;
}
S(const S &l, const S &r) {
len = 0;
rep(i, 0, l.len) pref[len++] = l.pref[i];
rep(i, 0, r.len) {
if (len == 0) pref[len++] = r.pref[i];
else {
pref[len] = r.pref[i];
pref[len].f |= pref[len - 1].f;
if (pref[len].f != pref[len - 1].f) ++len;
}
}
len = 0;
rep(i, 0, r.len) suff[len++] = r.suff[i];
rep(i, 0, l.len) {
if (len == 0) suff[len++] = l.suff[i];
else {
suff[len] = l.suff[i];
suff[len].f |= suff[len - 1].f;
if (suff[len].f != suff[len - 1].f) ++len;
}
}
ans = inf;
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)
ckmin(ans, r.pref[p].s - l.suff[s].s + 1);
}
}
};
int sz = 1;
S t[N << 1];
int query() { return t[1].ans; }
void update(int p, int v) {
p += sz;
for (t[p] = {p, 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;
while (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);
}
}
}
Compilation message
nekameleoni.cpp: In constructor 'S::S()':
nekameleoni.cpp:16:11: warning: 'S::ans' will be initialized after [-Wreorder]
int len, ans;
^~~
nekameleoni.cpp:16:6: warning: 'int S::len' [-Wreorder]
int len, ans;
^~~
nekameleoni.cpp:18:2: warning: when initialized here [-Wreorder]
S() : ans{inf}, len{0} { }
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
254 ms |
420988 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
267 ms |
420988 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
298 ms |
421112 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
740 ms |
421416 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1209 ms |
421708 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1327 ms |
421880 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1637 ms |
422172 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1588 ms |
421924 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2151 ms |
422144 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2164 ms |
422332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |