-
Notifications
You must be signed in to change notification settings - Fork 0
/
_a_XOR_value.cpp
95 lines (86 loc) · 2.49 KB
/
_a_XOR_value.cpp
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include <iostream>
using namespace std;
template <typename T> inline void inp (T &n) {
n = 0;
int ch = getchar_unlocked (), sign = 1;
while (ch < '0' || ch > '9') {
if (ch == '-') sign = -1; // only if also negative integer
ch = getchar_unlocked ();
}
while (ch >= '0' && ch <= '9')
n = (n << 3) + (n << 1) + ch - '0', ch = getchar_unlocked ();
n *= sign; // only if also negative integer
}
inline int inp () {
int n = 0;
int ch = getchar_unlocked (), sign = 1;
while (ch < '0' || ch > '9') {
if (ch == '-') sign = -1; // only if also negative integer
ch = getchar_unlocked ();
}
while (ch >= '0' && ch <= '9')
n = (n << 3) + (n << 1) + ch - '0', ch = getchar_unlocked ();
n *= sign; // only if also negative integer
return n;
}
template <typename T> inline void puti (T n, char lc) {
if (0 == n) {
putchar_unlocked ('0');
if (lc) putchar_unlocked (lc);
return;
}
bool sign = false;
if (n < 0) sign = true, n = -n;
char s[20]; int rdi =-1;
while (n) {
s [++rdi] = '0' + n % 10;
n /= 10;
}
if (sign) putchar_unlocked ('-');
while (rdi >= 0) putchar_unlocked (s [rdi--]);
if (lc) putchar_unlocked (lc);
}
inline void puts (string s) {
for (char c : s) putchar_unlocked (c);
}
inline void inps (string &i) {
i = "";
char temp = getchar_unlocked ();
while (temp == '\n' or temp == ' ') temp = getchar_unlocked ();
while (temp != '\n' and temp != ' ' and temp != EOF) i += temp, temp = getchar_unlocked ();
}
inline void inpc (char &i) {
char temp = getchar_unlocked ();
while (temp == '\n' or temp == ' ') temp = getchar_unlocked ();
if (temp != EOF) i = temp;
}
inline char inpc () {
char temp = getchar_unlocked ();
while (temp == '\n' or temp == ' ') temp = getchar_unlocked ();
if (temp != EOF) return temp;
else return '\n';
}
int main () {
/*ios_base :: sync_with_stdio (false);
cin.tie (NULL);
cout.tie (NULL);*/
int i, j, t, n, n2, ct;
long long ans, pow2i;
inp (t);
while (t--) {
inp (n);
n2 = n / 2;
ans = 0;
long long a [n];
for (i = 0; i < n; i++) inp (a [i]);
for (i = 0; i < 60; i++) {
ct = 0;
pow2i = (long long) 1 << i;
for (j = 0; j < n; j++)
if (a [j] & pow2i) ct++;
if (ct > n2) ans += pow2i;
}
puti (ans, '\n');
}
return 0;
}