QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#635690 | #8719. 后继 | ainuo | RE | 0ms | 0kb | C++14 | 1.1kb | 2024-10-12 20:36:33 | 2024-10-12 20:36:38 |
answer
#include<bits/stdc++.h>
using namespace std;
const int N=4e5+10;
int p[N];
int num[N][32];
int ans[32];
int n,m,len=0;
int query(int u)
{
int f;
cout<<"? "<<u<<'\n';
cin>>f;
return f;
}
void solve()
{
int dx=0;
for(int i=len;i>=1;i++)
{
int flg_0=0,flg_1=0;
for(int j=1;j<=n;j++)
{
if(num[j][i]==1) flg_1=1;
if(num[j][i]==0) flg_0=1;
}
if(flg_0==0||flg_1==0)
{
ans[i]=0;
continue;
}
int d=1+dx;
int t=query(d);
if(t==-1)
{
dx++;
d=1+dx;
t=query(d);
}
if(num[t][i]==num[d][i]) ans[i]=num[t][i];
else ans[i]=1-num[t][i];
}
}
int main()
{
cin>>n>>m;
for(int i=1;i<=n;i++) cin>>p[i];
for(int i=1;i<=n;i++)
{
int x=p[i],cnt=0;
while(x)
{
num[i][++cnt]=x%2;
x/=2;
}
len=max(len,cnt);
}
while(m--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Runtime Error
input:
5 1 1 2 3 4 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5
output:
? 1 ? 1 ? 1 ? 1 ? 1 ? 1 ? 1 ? 1 ? 1 ? 1 ? 1 ? 1 ? 1 ? 1 ? 1 ? 1