Pagini recente » Cod sursa (job #4460) | Cod sursa (job #322184) | Cod sursa (job #3354) | Cod sursa (job #852549) | Cod sursa (job #2931357)
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dbg(...) 69
#define nl(...) 42
#endif
#define ll long long
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll random(ll st, ll dr) {
assert(st <= dr);
return st + rng() % (dr - st + 1);
}
const int MOD = 1e9 + 7;
const int N = 2e5 + 10;
const int ALPHA = 2;
struct Node {
int index;
Node* sons[ALPHA];
Node() : index(0) {
memset(sons, 0, sizeof(sons));
}
};
int decode(char c) {
return c - 'a';
}
void add(Node* root, int x, int bit, int index) {
if (bit == -1) {
root->index = index;
return;
}
int currBit = (x & (1 << bit)) > 0;
if (!(root->sons[currBit])) {
root->sons[currBit] = new Node();
}
add(root->sons[currBit], x, bit - 1, index);
}
pair<int, int> dive(Node *root, int x, int bit, int gain) {
if (bit == -1) {
return {gain, root->index};
}
int currBit = (x & (1 << bit)) > 0;
if (root->sons[!currBit]) {
return dive(root->sons[!currBit], x, bit - 1, gain + (1 << bit));
} else {
return dive(root->sons[currBit], x, bit - 1, gain);
}
}
int n, x;
void solve(int test, istream &cin, ostream &cout) {
cin >> n;
Node* root = new Node();
add(root, 0, 20, 0);
int mx = 0;
int st, dr;
int s = 0;
for (int i = 1; i <= n; i++) {
cin >> x;
s ^= x;
auto ans = dive(root, s, 20, 0);
if (ans.first > mx) {
mx = ans.first;
dr = i;
st = ans.second + 1;
}
add(root, s, 20, i);
}
cout << mx << ' ' << st << ' ' << dr;
}
int main() {
ifstream cin("xormax.in");
ofstream cout("xormax.out");
ios_base::sync_with_stdio(0);
cin.tie(NULL);
auto start = std::chrono::high_resolution_clock::now();
bool multiTest = false;
int t;
if (multiTest) {
cin >> t;
} else {
t = 1;
}
for (int test = 1; test <= t; test++) {
solve(test, cin, cout);
}
auto stop = std::chrono::high_resolution_clock::now();
auto duration = std::chrono::duration_cast<std::chrono::microseconds>(stop - start);
// cerr << fixed << setprecision(6) << "Running time: " << (double) duration.count() / 1e6 << " seconds" << '\n';
return 0;
}