Pagini recente » Cod sursa (job #1555273) | Cod sursa (job #2538685) | Cod sursa (job #2304522) | Cod sursa (job #1062187) | Cod sursa (job #2655675)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("xormax.in");
ofstream fout("xormax.out");
const int nmax = 100005, inf = 1e9;
int n, v[nmax], ans = -1, a, b;
struct Trie{
int pos;
Trie *fiu[2];
Trie(){
pos = 0;
fiu[0] = fiu[1] = nullptr;
}
}*root = new Trie();
void Add(Trie *nod, int nr, int id, int i){
if (i == -1){
nod->pos = id;
return;
}
int bit = ((nr >> i) & 1);
if (nod->fiu[bit] == nullptr){
nod->fiu[bit] = new Trie();
}
return Add(nod->fiu[bit], nr, id, i - 1);
}
int Find(Trie *nod, int nr, int i){
if (i == -1){
return nod->pos;
}
int bit = ((nr >> i) & 1);
if (nod->fiu[1 - bit] != nullptr){
return Find(nod->fiu[1 - bit], nr, i - 1);
}
return Find(nod->fiu[bit], nr, i - 1);
}
int main(){
fin >> n;
Add(root, v[0], 0, 20);
for (int i = 1; i <= n; ++i){
fin >> v[i];
v[i] ^= v[i - 1];
int pos = Find(root, v[i], 20);
if ((v[i] ^ v[pos]) > ans){
ans = (v[i] ^ v[pos]);
a = pos + 1;
b = i;
}
Add(root, v[i], i, 20);
}
fout << ans << " " << a << " " << b << "\n";
fin.close();
fout.close();
return 0;
}