QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#479312#8719. 后继a2513472504WA 1ms5692kbC++171.7kb2024-07-15 16:20:252024-07-15 16:20:25

Judging History

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

  • [2024-07-15 16:20:25]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5692kb
  • [2024-07-15 16:20:25]
  • 提交

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=0;i<=29;i++)node[i]=-1;
    for(int i=1;i<=n;i++)cin>>a[i],ins(i),p[i]=i;
    
    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: 5692kb

input:

5 1
1 2 3 4 5

output:

? 0

result:

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