#include <iostream>
using namespace std;
const int N = 2.5e5 + 10;
const int LG = 29;
int n, x, a[N];
struct Trie {
struct node {
int child[2];
node () {
child[0] = child[1] = -1;
}
};
node nd[N * (LG + 1)];
int cnt;
void reset() {
cnt = 0;
nd[0] = node();
}
void add(int u) {
int cur = 0;
for (int i = LG; i >= 0; --i) {
int c = u >> i & 1;
if (nd[cur].child[c] == -1) {
nd[cur].child[c] = ++cnt;
nd[cnt] = node();
}
cur = nd[cur].child[c];
}
}
int Max(int u) {
int res = 0, cur = 0;
for (int i = LG; i >= 0; --i) {
int c = u >> i & 1;
if (nd[cur].child[c ^ 1] != -1) {
res |= (1 << i);
cur = nd[cur].child[c ^ 1];
} else {
cur = nd[cur].child[c];
}
}
return res;
}
} T;
int check(int val) {
int mx = 0, I = 0;
T.reset();
for (int i = n - val + 1; i >= 1; --i) {
T.add(a[i + val]);
int cur = T.Max(a[i]);
if (cur >= x) I = i;
}
return I;
}
int main() {
cin.tie(0); cout.tie(0);
ios_base::sync_with_stdio(false);
cin >> n >> x;
for (int i = 1; i <= n; ++i) cin >> a[i];
for (int i = n; i >= 1; --i) a[i] ^= a[i + 1];
int l = 1, r = n, ans = -1;
int I = 0;
while (l <= r) {
int mid = (l + r) >> 1;
int cur = check(mid);
if (cur > 0) {
ans = mid;
I = cur;
l = mid + 1;
} else {
r = mid - 1;
}
}
cout << I << " " << ans << "\n";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |