#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = (int)3e5 + 5, lg = 32;
int id, X;
vector<int> mn(N * lg);
vector<vector<int>> ch(N * lg, vector<int>(2, -1));
void add(int vl, int ind) {
int cur = 0;
for (int i = lg - 1; i >= 0; i--) {
bool bit = vl >> i & 1;
if (!~ch[cur][bit]) ch[cur][bit] = ++id;
cur = ch[cur][bit]; mn[cur] = ind;
}
}
int g(int A, int B) {
int cur = 0, ans = INT_MAX;
for (int i = lg - 1; i >= 0; i--) {
int a = (A >> i) & 1, b = (B >> i) & 1;
for (int j = 0; j < 2; j++) {
if (!~ch[cur][j]) continue;
if ((b ^ j) == a) cur = ch[cur][j];
else if ((b ^ j) > a) ans = min(ans, mn[ch[cur][j]]);
}
}
return ans;
}
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
int n;
cin >> n >> X;
add(0, 0);
int hr = 0, L = 0, K = 0;
for (int i = 1; i <= n; i++) {
int x;
cin >> x;
hr ^= x;
int l = g(X, hr);
if (K < i - l) {
L = l; K = i - l;
}
add(hr, i);
}
cout << L + 2 << ' ' << K;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |