#include <bits/stdc++.h>
using namespace std;
const int mxN = 550005;
#define int long long
int a[mxN];
struct Node{
Node* children[2];
int mn_idx;
Node(){
children[0] = children[1] = NULL;
mn_idx = mxN;
}
};
struct Trie{
Node* root = new Node();
void add(int val, int idx){
Node* curr = root;
for(int i = 62; i >= 0; --i){
int curr_bit = (val & (1ll << i)) > 0;
if(curr -> children[curr_bit] == NULL) curr -> children[curr_bit] = new Node();
curr = curr -> children[curr_bit];
curr -> mn_idx = min(curr -> mn_idx, idx);
}
}
int query(int val, int idx){
Node* curr = root;
int ans = 0;
for(int i = 62; i >= 0; --i){
int curr_bit = (val & (1ll << i)) > 0;
if(curr -> children[1 - curr_bit] != NULL && curr -> children[1 - curr_bit] -> mn_idx <= idx){
ans |= 1ll << i;
curr = curr -> children[1 - curr_bit];
}else{
if(curr -> children[curr_bit] -> mn_idx > idx) break;
curr = curr -> children[curr_bit];
}
}
return ans;
}
} tr;
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(nullptr); cout.tie(nullptr);
int n, x, pref = 0, best = 0, idx = 0;
cin >> n >> x;
for(int i = 1; i <= n; ++i){
cin >> a[i];
tr.add(pref, i);
pref ^= a[i];
int st = 1, en = i;
while(st <= en){
int mid = st + (en - st) / 2;
if(tr.query(pref, mid) >= x){
if((i - mid + 1) == best){
if(idx == 0) idx = mid;
else idx = min(idx, mid);
}else if((i - mid + 1) > best){
best = i - mid + 1;
idx = mid;
}
en = mid - 1;
}else{
st = mid + 1;
}
}
}
cout << idx << " " << best << "\n";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |