A2030 [蓝桥杯 2021 省 A] 异或数列
标程
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int T;
cin >> T;
while (T--) {
int n;
cin >> n;
vector<int> x(n);
int s = 0;
for (int i = 0; i < n; ++i) {
cin >> x[i];
s ^= x[i];
}
if (s == 0) {
cout << 0 << "\n";
continue;
}
int k = 0;
while ((1 << (k + 1)) <= s) ++k;
int cnt = 0;
for (int i = 0; i < n; ++i)
if (x[i] >> k & 1) ++cnt;
if (cnt == 1 || (n & 1)) cout << 1 << "\n";
else cout << -1 << "\n";
}
return 0;
}