QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#417536#8719. 后继grass8cow#WA 1ms3876kbC++171.0kb2024-05-22 19:36:452024-05-22 19:36:46

Judging History

你现在查看的是最新测评结果

  • [2024-05-22 19:36:46]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3876kb
  • [2024-05-22 19:36:45]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
int n,m,X;
int ch[12200100][2],cn,id[12001000];
int lx[30];
int main(){
    scanf("%d%d",&n,&m);
    for(int i=1,a;i<=n;i++){
        scanf("%d",&a);
        int u=1;
        for(int j=29;j>=0;j--){
            int p=((a>>j)&1);
            if(!ch[u][p]){
                ch[u][p]=++cn;
                if(ch[u][0]&&ch[u][1])lx[j]=u;
            }
            u=ch[u][p];
        }
        id[u]=i;
    }
    for(int i=1;i<=m;i++){
        int x=0;
        for(int j=0;j<30;j++)if(lx[j]){
            int u=ch[lx[j]][0],v=ch[lx[j]][1];
            for(int k=j-1;k>=0;k--){
                int p=((x>>k)&1);
                if(ch[u][p^1])u=ch[u][p^1];
                else u=ch[u][p];
                if(ch[v][p])v=ch[v][p];
                else v=ch[v][p^1];
            }
            printf("? %d\n",id[u]);fflush(stdout);
            int e;scanf("%d",&e);
            if(e!=id[v])x|=(1<<j);
        }
        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: 3876kb

input:

5 1
1 2 3 4 5
-1

output:

? 4
! 1

result:

wrong answer 1st numbers differ - expected: '3', found: '1'