QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#602684 | #8719. 后继 | ucup-team902# | WA | 1ms | 8044kb | C++17 | 1.8kb | 2024-10-01 12:03:16 | 2024-10-01 12:03:16 |
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];
}
printf("%d %d\n",pos,u);
id[u]=pos;
}
void prep(int u,int k){
if(k>=0&&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){
// printf("%d\n",u);
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){
// printf("%d\n",u);
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: 1ms
memory: 8044kb
input:
5 1 1 2 3 4 5 -2
output:
1 31 2 33 3 34 4 37 5 38 ? 4 ? 1
result:
wrong answer 1st numbers differ - expected: '3', found: '-114514'