# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
729342 | finn__ | XOR (IZhO12_xor) | C++17 | 216 ms | 58464 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;
constexpr size_t L = 30;
struct Trie
{
Trie *c[2];
unsigned subtree_min;
Trie() { c[0] = c[1] = 0, subtree_min = UINT_MAX; }
void insert(unsigned x, unsigned j, unsigned i = 0)
{
if (i == L)
{
subtree_min = min(subtree_min, j);
return;
}
bool z = x & (1 << (L - i - 1));
if (!c[z])
c[z] = new Trie();
c[z]->insert(x, j, i + 1);
subtree_min = min(c[0] ? c[0]->subtree_min : UINT_MAX,
c[1] ? c[1]->subtree_min : UINT_MAX);
}
unsigned get_earliest_ge(unsigned x, unsigned y, unsigned i = 0)
{
if (i == L)
return subtree_min;
bool z = x & (1 << (L - i - 1));
if (y & (1 << (L - i - 1)))
{
return c[!z] ? c[!z]->get_earliest_ge(x, y, i + 1) : UINT_MAX;
}
else
{
return min(c[z] ? c[z]->get_earliest_ge(x, y, i + 1) : UINT_MAX,
c[!z] ? c[!z]->subtree_min : UINT_MAX);
}
}
};
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
size_t n;
unsigned y;
cin >> n >> y;
unsigned pxor = 0, i = 0, k = 0;
Trie t;
t.insert(0, 0);
for (size_t j = 1; j <= n; ++j)
{
unsigned a;
cin >> a;
pxor ^= a;
unsigned h = t.get_earliest_ge(pxor, y);
if (h != UINT_MAX && j - h > k)
k = j - h, i = h;
t.insert(pxor, j);
}
cout << i + 1 << ' ' << k << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |