# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
98552 | luciocf | XOR (IZhO12_xor) | C++14 | 588 ms | 58712 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;
const int maxn = 3e5;
struct node
{
node *b[2];
int menor;
node()
{
b[0] = b[1] = NULL;
menor = 1e9+10;
}
};
int n, x;
int num[maxn], p[maxn];
void insert(node *at, int v, int ind)
{
for (int i = 30; i >= 0; i--)
{
bool d = (v&(1<<i));
at->menor = min(at->menor, ind);
if (!at->b[d]) at->b[d] = new node();
at = at->b[d];
}
at->menor = min(at->menor, ind);
}
int query(node *at, int v)
{
int ans = 0;
for (int i = 30; i >= 0; i--)
{
if (!at) return -1;
if (ans >= x) return at->menor;
bool d = (v&(1<<i));
if (d && at->b[0])
{
ans += (1<<i);
at = at->b[0];
}
else if (d) at = at->b[1];
if (!d && at->b[1])
{
ans += (1<<i);
at = at->b[1];
}
else if (!d) at = at->b[0];
}
if (ans >= x) return at->menor;
return -1;
}
int main(void)
{
ios::sync_with_stdio(false); cin.tie(0);
cin >> n >> x;
node *root = new node();
for (int i = 1; i <= n; i++)
{
cin >> num[i];
p[i] = p[i-1]^num[i];
}
int ans = 0, ind;
for (int i = 1; i <= n; i++)
{
insert(root, p[i-1], i-1);
int pos = query(root, p[i]);
if (pos == -1) continue;
if (i-pos > ans)
{
ans = i-pos;
ind = pos+1;
}
}
cout << ind << " " << ans << "\n";
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |