QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#479309#8719. 后继a2513472504RE 0ms0kbC++171.8kb2024-07-15 16:19:302024-07-15 16:19:31

Judging History

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

  • [2024-07-15 16:19:31]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-07-15 16:19:30]
  • 提交

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(){
    freopen("./aa.in", "r", stdin);
    freopen("./aa.out", "w", stdout);
    std::ios::sync_with_stdio(0);
    std::cin.tie(0);
    std::cout.tie(0);
    int t = 1;
    cin>>n>>t;
    for(int i=1;i<=n;i++)cin>>a[i],ins(i),p[i]=i;
    for(int i=0;i<=29;i++)node[i]=-1;
    while (t--)
    {
        solve();
    }
	return 0;
}

详细

Test #1:

score: 0
Dangerous Syscalls

input:


output:


result: