# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1092412 | juicy | XOR (IZhO12_xor) | C++17 | 1568 ms | 24664 KiB |
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>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
const int N = 25e4 + 5, M = 7500005, LG = 30;
int n, k, node = 1;
int a[N], nxt[M][2], lst[M];
void reset() {
while (node) {
nxt[node][0] = nxt[node][1] = lst[node] = 0;
--node;
}
node = 1;
}
void add(int x, int i) {
int p = 1;
for (int j = LG - 1; ~j; --j) {
int c = x >> j & 1;
if (!nxt[p][c]) {
nxt[p][c] = ++node;
}
p = nxt[p][c];
}
if (!lst[p]) {
lst[p] = i;
}
}
array<int, 2> qry(int x) {
int m = 0, p = 1;
for (int j = LG - 1; ~j; --j) {
int c = x >> j & 1;
if (nxt[p][c ^ 1]) {
m += 1 << j;
p = nxt[p][c ^ 1];
} else {
assert(nxt[p][c]);
p = nxt[p][c];
}
}
assert(lst[p]);
return {m, lst[p]};
}
int check(int m) {
reset();
for (int i = 1, j = 0; i <= n; ++i) {
while (j <= i - m) {
add(a[j], j + 1);
++j;
}
if (i >= m) {
auto [x, l] = qry(a[i]);
if (x >= k) {
return l;
}
}
}
return 0;
}
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
cin >> n >> k;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
a[i] ^= a[i - 1];
}
int l = 1, r = n, p = -1, len = -1;
while (l <= r) {
int m = (l + r) / 2;
int i = check(m);
if (i) {
p = i;
len = m;
l = m + 1;
} else {
r = m - 1;
}
}
cout << p << " " << len << "\n";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |