#include <bits/stdc++.h>
#define int long long
#define l 1ll
#define endl '\n'
#define quickio ios::sync_with_stdio(false);
#define quickin cin.tie(nullptr);
#define quickout cout.tie(nullptr);
#define maxn 35
using namespace std;
int n, q, x, ans, tot, buk[maxn];
signed main() {
quickio
quickin
quickout
cin >> n;
for(int i = 1; i <= n; i++) {
cin >> x; int num = 1;
while(x) buk[num] += x & 1, x >>= l, num++;
}
cin >> q;
while(q--) {
ans = tot = 0, cin >> x;
for(int i = 34; i >= 1; i--)
if(buk[i] >= n - buk[i]) tot += (n - buk[i]) * (l << (i - 1)), ans += (l << (i - 1));
else tot += buk[i] * (l << (i - 1));
if(tot > x) {
cout << "-1\n";
} else {
for(int i = 34; i >= 1; i--)
if(!(ans & (l << (i - 1))) && tot + (n - buk[i] * 2) * (l << (i - 1)) <= x)
ans += l << (i - 1), tot += (n - buk[i] * 2) * (l << (i - 1));
cout << ans << endl;
}
}
return 0;
}
样例 2 输入 :
1
0
1
1073741824000000
样例 2 输出 :
1073741824000000
我的输出 :
17179869183
AC Record :