First of all the number of exclusive-OR sum and sum up to give some number of bits is 1 bit 0 is a 0 bit is a number of all there is an even number the number of
No matter how you divide the number of this one on the final answers are not contributing because of the even = even + even / odd + odd
So we put all direct & sum regardless of the number of those bits do not contribute to the re-insertion as a linear base
Come up with a maximum of 1 bit to A then we have to do now is to try to ensure that A high can not rest on the other 1 is 1 so the answer is optimal
#include<bits/stdc++.h> using namespace std; typedef long long ll; ll a[65]; ll num[100005]; ll x; int main () { int TNT; scanf("%d", &TNT); while (TNT--) { memset(a, 0, sizeof(a)); int n; ll sum = 0; scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%lld", &x); Surely, [i] = x; sum ^= x; } for (int i = 1; i <= n; i++) { num[i] &= sum; } for (int i = 1; i <= n; i++) { for (int j = 62; j >= 0; j--) { if (num[i] & (1ll << j)) { if (!a[j]) { a[j] = num[i]; break; } else { num [i] '= a [j]; } } } } int aim = -1; ll aimx = 0; for (int i = 62; i >= 0; i--) { if (sum & (1ll << i)) { aim = i; aimx = a[i]; break; } } for (int i = aim - 1; i >= 0; i--) { if (aimx & (1ll << i)) { aimx ^= a[i]; } } ll ans = aimx - (aimx ^ sum); printf("%lld\n", ans); } }