提交时间:2021-12-06 13:56:12
运行 ID: 33471
#include <bits/stdc++.h> using namespace std; const int logw = 32; struct node { int son[2]; int vis, num; node(int son1 = 0, int son2 = 0, int vis = 0, int num = 0) : son {son1, son2}, vis(vis), num(num) {} }; vector<node> t(1); #define int long long inline int read() { int x=0; char c=getchar(); for(; c<'0' || c>'9'; c=getchar()); for(; c<='9' && c>='0'; c=getchar()) x=(x<<3)+(x<<1)+c-'0'; return x; } void add(int x) { t[0].vis++; int p = 0; for (int i = logw; i >= 0; i--) { bool wz = (x >> i) & 1; if (!t[p].son[wz]) t.push_back({}), t[p].son[wz] = t.size() - 1; p = t[p].son[wz]; t[p].vis++; } t[p].num = x; } void del(int x) { t[0].vis--; int p = 0; for (int i = logw; i >= 0; i--) { bool wz = (x >> i) & 1; p = t[p].son[wz]; if (p) t[p].vis--; } } int solve(int x) { int p = 0; for (int i = logw; i >= 0; i--) { bool wz = (x >> i) & 1; if (t[p].son[!wz] && t[t[p].son[!wz]].vis) p = t[p].son[!wz]; else p = t[p].son[wz]; } return t[p].num; } int q, n, a[1005]; signed main() { //freopen("chip.in","r",stdin); //freopen("chip.out","w",stdout); q = read(); while (q--) { // printf("Case #%d:\n", ++qq); int ans = -1; t.assign(1, {0,0,0,0}); n = read(); for (int i = 1; i <= n; i++) { a[i] = read(); add(a[i]); } for (int i = 1; i <= n; i++) { for (int j = i + 1; j <= n; j++) { del(a[i]); del(a[j]); ans = max(ans, (a[i] + a[j]) ^ solve(a[i] + a[j])); add(a[i]); add(a[j]); } } printf("%lld\n", ans); } return 0; }