后四个点一直wa,试了__int128
也不行
#include<bits/stdc++.h>
#define int long long
using namespace std;
inline int read() {
int res=0, f=1;char ch=getchar();
while (ch<'0'||ch>'9') {
if (ch=='-')f=-1;
ch=getchar();
}
while (ch>='0'&&ch<='9')res=res*10+ch-48, ch=getchar();
return res*f;
}
const int maxn = 100050;
int a[maxn],n,m,q;
int cnt[99];//1的个数
signed main() {
n=read();
for(register int i=1;i<=n;i++)a[i]=read();
q=read();
for(register int i=1;i<=n;i++){
int tmp = a[i],ct=0;
while(tmp){
if(tmp&1)cnt[ct]++;
ct++;
tmp>>=1;
}
}
int mid = n>>1;
int mink=0,S=0;
for(register int i=0;i<=32;i++){
if(cnt[i]<mid)S+=(1<<i)*cnt[i];//k在这一位选0
else S +=(1<<i)*(n-cnt[i]),mink+=1<<i;
}
while(q--){
int m=read();
if(S>m){
cout<<-1<<endl;
continue;
}
else{
int ans =mink ;
int cur =S;
for(register int i=30;i>=0;i--){
int tmp = (ans>>i)&1;
if(tmp)continue;
if((cur+(1<<i)*(n-cnt[i]-cnt[i])<=m)ans+=1<<i,cur=cur+(1<<i)*(n-cnt[i]-cnt[i]);
}
cout<<ans<<endl;
}
}
return 0;
}