QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#479311 | #8719. 后继 | a2513472504 | WA | 1ms | 7708kb | C++17 | 1.7kb | 2024-07-15 16:19:50 | 2024-07-15 16:19:50 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pis = pair<ll,ll>;
const int N = 4e5+200;
const ll inf=1e9;
const ll mod=998244353;
const ll k=15;
int nxt[N*30][2],val[N*30],a[N],n,m,tot,node[31],bit[31],p[N];
int ask(int x){
cout<<"? "<<x<<endl;
int ret;
cin>>ret;
return ret;
}
void ins(int x){
int now=0;
for(int i=29;i>=0;i--){
int bit=(a[x]>>i)&1;
if(!nxt[now][bit])nxt[now][bit]=++tot;
if(nxt[now][0]&&nxt[now][1])node[i]=now;
now=nxt[now][bit];
}
val[now]=x;
}
int getid(int now,int h,int need){
if(h==-1)return now;
if(!nxt[now][0]&&!nxt[now][1])return now;
if(nxt[now][need^bit[h]])return getid(nxt[now][need^bit[h]],h-1,need);
return getid(nxt[now][need^bit[h]^1],h-1,need);
}
void solve(){
for(int i=0;i<30;i++)bit[i]=0;
ll ans=0;
for(int i=0;i<30;i++){
if(node[i]!=-1)continue;
int now=node[i];
int id1=getid(nxt[now][0],i-1,1),id2=getid(nxt[now][1],i-1,0);
ll ret=ask(val[id1]);
if(ret!=val[id2])bit[i]=1;
}
for(int i=0;i<=29;i++)ans+=(1ll<<i)*bit[i];
cout<<"! "<<ans<<endl;
cout.flush();
}
void none(){
sort(p+1,p+1+n,[](int aa,int bb){
return (a[aa]^543703040)<(a[bb]^543703040);
});
for(int i=1;i<=n;i++)cout<<p[i]<<'\n';
// dfs(0,29);
// for(int i=1;i<=m;i++)work();
}
signed main(){
int t = 1;
cin>>n>>t;
for(int i=1;i<=n;i++)cin>>a[i],ins(i),p[i]=i;
for(int i=0;i<=29;i++)node[i]=-1;
while (t--)
{
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 7708kb
input:
5 1 1 2 3 4 5
output:
? 0
result:
wrong answer Answer contains longer sequence [length = 1], but output contains 0 elements