#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
using namespace std;
// using namespace __gnu_pbds;
// template<class T>
// using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define SPEED ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
#define pb push_back
#define fi first
#define se second
// #define endl "\n"
#define ALL(x) x.begin(), x.end()
#define sz(x) x.size()
#define intt long long
const intt mod = 1e9 + 7;
const intt inf = 1e18;
const intt mxN = 2e5 + 5;
vector<intt> A(mxN), pref(mxN);
vector<vector<intt>> trie(mxN, vector<intt>(2));
vector<intt> idx(mxN);
intt avil = 1;
void add(intt X, intt idxi) {
intt node = 0;
for(intt i = 29; i >= 0; i--) {
intt bit = ((1 << i) & X) > 0;
if(trie[node][bit] == 0) {
trie[node][bit] = avil;
node = trie[node][bit];
idx[node] = idxi;
avil++;
} else {
node = trie[node][bit];
}
}
}
intt get(intt num, intt x) {
intt node = 0, ret = inf, ret2 = 0;
for(intt i = 29; i >= 0; i--) {
intt numbit = ((1 << i) & num) > 0;
intt Xbit = ((1 << i) & num) > 0;
if(Xbit == 0) {
intt eks = (numbit ^ 1);
if(trie[node][eks]) {
ret = min(ret, idx[trie[node][eks]]);
}
node = trie[node][numbit];
} else {
if(trie[node][!numbit] == 0) {
return ret;
}
node = trie[node][!numbit];
}
ret2 = idx[node];
}
return min(ret, ret2);
}
void solve() {
intt N, x;
cin >> N >> x;
A.resize(N);
for(auto &a : A) cin >> a;
pref.resize(N);
for(intt i = 0; i < N; i++) {
pref[i] = A[i];
if(i) pref[i] ^= pref[i-1];
}
// for(intt i : pref) cout << i << " ";
// cout << endl;
intt diff = 0, l = 0, r = 0;
add(pref[0], 0);
for(intt i = 1; i < N; i++) {
intt for_l = get(pref[i], x);
// cout << i << ": " << for_l << endl;
if(for_l == -1) continue;
if(i - for_l > diff) {
r = i + 1;
l = for_l + 1;
diff = i - for_l;
}
add(pref[i], i);
}
l++;
cout << l << " " << r-l+1 << endl;
}
signed main() {
SPEED;
intt tst = 1;
// cin >> tst;
while (tst--) {
solve();
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |