Pagini recente » Cod sursa (job #527583) | Cod sursa (job #12704) | Cod sursa (job #1783059) | Cod sursa (job #1343699) | Cod sursa (job #2660728)
#include <bits/stdc++.h>
#define debug(x) cerr << #x << " " << x << "\n"
#define debug_with_space(x) cerr << #x << " " << x << " "
using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, pii> piii;
const ll NMAX = 100001;
const ll INF = (1LL << 50);
const ll MOD = 1000000007;
const ll BLOCK = 101;
const ll nr_of_bits = 22;
class Trie{
struct Node{
int ap = 0;
int sf = 0;
Node* v[2];
Node(){
ap = sf = 0;
for(int i = 0;i < 2;i++){
v[i] = NULL;
}
}
};
void add(Node* &node, string s, int k, int val){
if(node == NULL){
node = new Node();
}
node->ap = val;
if(k == s.size()){
node->sf = val;
return;
}
int poz = s[k] - '0';
add(node->v[poz], s, k + 1, val);
}
int query(Node* &node, string s, int k){
if(node == NULL){
return 0;
}
if(node->ap == 0)
return 0;
if(s.size() == k){
return node->ap;
}
int poz = s[k] - '0';
return query(node->v[poz], s, k + 1);
}
Node* root;
public:
void insert(string s, int i){
add(root, s, 0, i);
}
void erase(string s){
add(root, s, 0, -1);
}
int find(string s){
return query(root, s, 0);
}
}trie;
int main() {
ifstream cin("xormax.in");
ofstream cout("xormax.out");
int n, i, cnt = 0;
pii sol;
int xxor = 0, maxim = 0;
cin >> n;
while(n--){
int x;
cin >> x;
cnt++;
xxor ^= x;
string c = "";
for(int i = nr_of_bits; i >= 0;i--){
if(xxor & (1 << i))
c += "1";
else
c += "0";
}
//cout << c << " ";
trie.insert(c, cnt);
string comp = "";
int pz = 0;
int scor = 0;
for(int i = nr_of_bits; i >= 0; i--){
char cc;
if(c[nr_of_bits - i] == '0')
cc = '1';
else
cc = '0';
if(trie.find((comp + cc))){
comp += cc;
scor += (1 << i);
}else{
comp += c[nr_of_bits - i];
}
}
//cout << comp << "\n";
pz = trie.find(comp);
if(scor > maxim){
maxim = scor;
sol = {pz + 1, cnt};
}
}
cout << maxim << " ";
cout << sol.first << " " << sol.second;
return 0;
}