QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#417912#8719. 后继ucup-team1338#WA 1ms5788kbC++201.5kb2024-05-23 01:36:232024-05-23 01:36:24

Judging History

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

  • [2024-05-23 01:36:24]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5788kb
  • [2024-05-23 01:36:23]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

const int N=400014;

int a[N],n;
int q[30];
int tr[N*30][2],t=1,id[N*30];
void ins(int x,int I){
    int p=1;
    for(int i=29;~i;i--){
        int&k=tr[p][x>>i&1];
        if(!k)k=++t;p=k;
    }
    id[p]=I;
}

void dfs(int x,int dep,int nw){
    if(dep<0)return;
    if(tr[x][0]&&tr[x][1])q[dep-1]=nw;
    if(tr[x][0])dfs(tr[x][0],dep-1,nw);
    if(tr[x][1])dfs(tr[x][1],dep-1,nw+(1<<(dep-1)));
}
int ans=0;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin>>n;int m;
    memset(q,-1,sizeof q);
    cin>>m;
    for(int i=1;i<=n;i++)cin>>a[i],ins(a[i],i);
    dfs(1,30,0);
    while(m--){
        ans=0;
        for(int y,p,i=0;i<30;i++)if(~q[i]){
            p=1;
            for(int j=29;j>=i;j--)p=tr[p][q[i]>>j&1];
            for(int j=i-1;~j;j--){
                if(ans>>j&1){if(tr[p][0])p=tr[p][0];else p=tr[p][1];}
                else{if(tr[p][1])p=tr[p][1];p=tr[p][0];}
            }
            cout<<"? ";
            cout<<id[p]<<endl;
            cin>>y;
            q[i]^=1<<i;
            p=1;
            for(int j=29;j>=i;j--)p=tr[p][q[i]>>j&1];
            for(int j=i-1;~j;j--){
                if(ans>>j&1){if(tr[p][1])p=tr[p][1];else p=tr[p][0];}
                else{if(tr[p][0])p=tr[p][0];p=tr[p][1];}
            }
            if(y!=id[p])ans+=1<<i;
            q[i]^=1<<i;
        }
        cout<<"! ";
        cout<<ans<<endl;
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5788kb

input:

5 1
1 2 3 4 5
-1
5
5

output:

? 4
? 1
? 1
! 3

result:

ok 1 number(s): "3"

Test #2:

score: 0
Accepted
time: 0ms
memory: 5740kb

input:

1 1
0

output:

! 0

result:

ok 1 number(s): "0"

Test #3:

score: -100
Wrong Answer
time: 0ms
memory: 3616kb

input:

10 10
380864879 387438357 21484978 21099484 375657510 23189485 24467021 379687119 386094773 15156199

output:

? 0

result:

wrong answer Answer contains longer sequence [length = 10], but output contains 0 elements