Pagini recente » Cod sursa (job #569530) | Cod sursa (job #2565581) | Cod sursa (job #467800) | Cod sursa (job #267180) | Cod sursa (job #2647817)
#include <bits/stdc++.h>
#define newline '\n'
using namespace std;
ifstream fin("xormax.in");
ofstream fout("xormax.out");
///***********************
const int NMAX = 1e5 + 3, BITSMAX = 22;
struct Trie {
Trie *sons[2];
int pos;
Trie() {
sons[0] = sons[1] = nullptr;
pos = 0;
}
} *trie = new Trie();
int n, ps[NMAX];
inline void read() {
fin >> n;
for (int x, i = 1; i <= n; i++) {
fin >> x;
ps[i] = ps[i - 1] ^ x;
}
}
inline void addInTrie(Trie *node, int x, int pos, int cnt = BITSMAX) {
if (cnt < 0) {
node->pos = pos;
return;
}
bool bit = (x & (1 << cnt));
if (!node->sons[bit])
node->sons[bit] = new Trie();
addInTrie(node->sons[bit], x, pos, cnt - 1);
}
inline int findInTrie(Trie *node, int x, int cnt = BITSMAX) {
if (cnt < 0)
return node->pos;
bool bit = (x & (1 << cnt));
if (node->sons[!bit])
bit = !bit;
return findInTrie(node->sons[bit], x, cnt - 1);
}
inline void solve() {
int p1, p2, ans = 0;
addInTrie(trie, 0, 0);
for (int i = 1; i <= n; i++) {
int j = findInTrie(trie, ps[i]);
if ((ps[i] ^ ps[j]) > ans) {
ans = (ps[i] ^ ps[j]);
p1 = j + 1;
p2 = i;
}
addInTrie(trie, ps[i], i);
}
fout << ans << ' ' << p1 << ' ' << p2 << newline;
}
int main() {
read();
solve();
fout.close();
return 0;
}