Pagini recente » Monitorul de evaluare | Cod sursa (job #3040600) | Cod sursa (job #2555029) | Cod sursa (job #58317) | Cod sursa (job #3340420)
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned ll;
using ld = long double;
#define all(v) begin(v), end(v)
#define al(v, l, r) begin(v) + l, begin(v) + r + 1
#define pb push_back
#define pob pop_back
#define sz(v) (int)v.size()
#define fs first
#define sd second
constexpr int inf = 2e9;
constexpr ll infll = 4e18;
constexpr int N = 1e5 + 5;
int n, a[N], p[N];
struct trie_nod {
vector<trie_nod*> v;
vector<int> idxs;
trie_nod(): v(2, nullptr) {}
};
signed main() {
ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
freopen("xormax.in", "r", stdin);
freopen("xormax.out", "w", stdout);
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
p[i] = p[i - 1] ^ a[i];
}
trie_nod *rad = new trie_nod();
int maxa = 0;
pair<int, int> pmax = {-1, -1};
for (int i = 1; i <= n; ++i) {
string s = bitset<22>(p[i]).to_string();
trie_nod *nod = rad;
for (char c : s) {
if (nod->v[c - '0'] == nullptr) {
nod->v[c - '0'] = new trie_nod();
}
nod = nod->v[c - '0'];
nod->idxs.pb(i);
}
}
for (int i = 1; i <= n; ++i) {
string s = bitset<22>(p[i]).to_string();
trie_nod *nod = rad;
string tmp = "";
for (char c : s) {
if (nod->v[(c - '0') ^ 1] != nullptr) {
nod = nod->v[(c - '0') ^ 1];
tmp += to_string((c - '0') ^ 1);
} else {
nod = nod->v[c - '0'];
tmp += c;
}
}
int cbst = p[i] ^ stoi(tmp, 0, 2); ///stoi(string, pozitie_inceput, baza_de_numeratie)
if (maxa < cbst) {
maxa = cbst;
pmax.fs = i;
for (int x : nod->idxs) {
if (x != i) {
pmax.sd = x;
break;
}
}
if (pmax.fs > pmax.sd) {
swap(pmax.fs, pmax.sd);
}
pmax.fs++;
}
}
cout << maxa << " " << pmax.fs << " " << pmax.sd;
}