QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#479197#8719. 后继a2513472504Compile Error//C++171.5kb2024-07-15 15:52:432024-07-15 15:52:43

Judging History

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

  • [2024-07-15 15:52:43]
  • 评测
  • [2024-07-15 15:52:43]
  • 提交

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(!nxt[now][0]&&!nxt[now][1])return now;
    int tmp=0;
    if(bit[h])tmp=1;
    if(nxt[now][need^tmp])return getid(nxt[now][need^tmp],h-1,need);
    return getid(nxt[now][need^tmp^1],h-1,need);
}

void work(){
    for(int i=0;i<30;i++)bit[i]=0;
    for(int i=0;i<30;i++){
        if(!node[i])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;
    }
    ll ans=0;
    for(int i=0;i<=29;i++)ans+=(1ll<<i)*bit[i];
    cout<<"! "<<ans<<endl;
    cout.flush();
}

void solve(){
    cin>>n>>m;
    for(int i=1;i<=n;i++)cin>>a[i],ins(i);
    dfs(0,29);
    for(int i=1;i<=m;i++)work();
}

signed main(){

    int t = 1;
    // cin>>t;
    while (t--)
    {
        solve();
    }
	return 0;
}

Details

answer.code: In function ‘void solve()’:
answer.code:60:5: error: ‘dfs’ was not declared in this scope; did you mean ‘ffs’?
   60 |     dfs(0,29);
      |     ^~~
      |     ffs