QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#602680 | #8719. 后继 | ucup-team902# | WA | 2ms | 7856kb | C++17 | 1.7kb | 2024-10-01 11:57:25 | 2024-10-01 11:57:25 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=4e5,S=2e7;
int n,m;
int a[N+5];
int qp[35];
struct Trie{
int ch[S+5][2],tot;
int id[S+5];
Trie(){ tot=1; }
void insert(int x,int pos){
int u=1;
for(int i=29;i>=0;i--){
int t=x>>i&1;
if(!ch[u][t]) ch[u][t]=++tot;
u=ch[u][t];
}
id[u]=pos;
}
void prep(int u,int k){
if(ch[u][0]&&ch[u][1]) qp[k]=u;
if(ch[u][0]) prep(ch[u][0],k-1);
if(ch[u][1]) prep(ch[u][1],k-1);
}
int qymx(int u,int x,int k){
if(k==-1) return id[u];
int lc=ch[u][0],rc=ch[u][1];
if(lc&&rc){
if(x>>k&1) return qymx(lc,x,k-1);
else return qymx(rc,x,k-1);
}
else return qymx(lc+rc,x,k-1);
}
int qymn(int u,int x,int k){
if(k==-1) return id[u];
int lc=ch[u][0],rc=ch[u][1];
if(lc&&rc){
if(x>>k&1) return qymn(rc,x,k-1);
else return qymn(lc,x,k-1);
}
else return qymn(lc+rc,x,k-1);
}
}T;
int main(){
scanf("%d %d",&n,&m);
for(int i=1;i<=n;i++){
scanf("%d",&a[i]);
T.insert(a[i],i);
}
T.prep(1,29);
while(m--){
int x=0;
for(int i=0;i<30;i++){
int u=qp[i];
if(u) continue;
int l=T.qymx(T.ch[u][0],x,i-1);
int r=T.qymn(T.ch[u][1],x,i-1);
printf("? %d\n",l);
fflush(stdout);
int q; scanf("%d",&q);
if(q!=r) x^=1<<i;
}
printf("! %d\n",x);
fflush(stdout);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 2ms
memory: 7856kb
input:
5 1 1 2 3 4 5
output:
? 0
result:
wrong answer Answer contains longer sequence [length = 1], but output contains 0 elements