-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1805a.cpp
More file actions
37 lines (33 loc) · 829 Bytes
/
1805a.cpp
File metadata and controls
37 lines (33 loc) · 829 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
vector<int> a(n);
int result = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
result = result^a[i];
}
if(n%2 == 1){
cout << result << "\n";
}else{
if(result == 0){
// cout << a[0] << "\n";
cout << result << "\n";
}else{
cout << -1 << "\n";
}
}
}
return 0;
}
// logic think of xor properties
// a xor a = 0
// a xor 0 = a
// so for n even as there will be n x ..x xor x ..which will give 0
// there will either the result be 0 or it wont be that is -1
// for n odd xor of all elements and that is the answer