QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#602987 | #8719. 后继 | UESTC_xxx# | WA | 1ms | 15904kb | C++14 | 2.3kb | 2024-10-01 13:57:04 | 2024-10-01 13:57:08 |
Judging History
answer
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cstring>
#include<queue>
#include<map>
#define LL long long
using namespace std;
const int mod=998244353;
const int Base=23,Base2=27;
inline int lowbit(int x){return x&(-x);}
inline int Jia(int x){return x>=mod?x-mod:x;}
inline int Jian(int x){return x>=0?x:x+mod;}
int KSM(int a,int b){
int Ans=1;
while(b){
if(b&1)Ans=1LL*Ans*a%mod;
a=1LL*a*a%mod;
b>>=1;
}
return Ans;
}
inline int read(){
int k=0,ty=1;
char ch=getchar();
while(ch<'0'||ch>'9'){
if(ch=='-')ty=-1;
ch=getchar();
}
while(ch<='9'&&ch>='0'){
k=k*10+ch-'0';
ch=getchar();
}
return k*ty;
}
int gcd(int a,int b){
if(!b)return a;
return gcd(b,a%b);
}
const int maxn=5e5+5;
int rt=1,all=1,ch[maxn][2],Size[maxn],id[maxn],ID[maxn][2],v[maxn],n,m;
int a[maxn],pos[maxn],DFN,ans[maxn],To[maxn];
void Insert(int x){
int p=rt,c;
for(int i=2;i>=0;--i){
if(a[x]&(1<<i))c=1;
else c=0;
if(!ch[p][c])ch[p][c]=++all;
// ID[p][c]=x;
if(ch[p][0]&&ch[p][1])v[i]=p;
p=ch[p][c];
}
pos[x]=p;To[p]=x;
}
void dfs(int x){
id[x]=++DFN;Size[x]=1;
if(ch[x][0])dfs(ch[x][0]);
if(ch[x][1])dfs(ch[x][1]);
Size[x]+=Size[ch[x][0]]+Size[ch[x][1]];
}
int Get(int x,int deep){
if(deep==-1)return To[x];
if(ch[x][ans[deep]^1])return Get(ch[x][ans[deep]^1],deep-1);
return Get(ch[x][ans[deep]],deep-1);
}
void Solve(){
for(int i=0;i<=30;++i){
// cout<<i<<'\n';
if(!v[i])ans[i]=0;
else {
// cout<<"SHIT\n";
int p=v[i];
int p2=Get(ch[p][0],i-1);
// cout<<p<<' '<<p2<<'\n';
cout<<"? "<<p2<<'\n';
cout.flush();
int t,t2=ch[p][1];
cin>>t;
// cout<<t<<'\n';
// cout<<"FAFAFFA\n";
if(t==-1){
ans[i]=1;
continue;
}
// cout<<"F1\n";
t=pos[t];
// cout<<"F2\n";
if(id[t2]<=id[t]&&id[t2]+Size[t2]>id[t])ans[i]=0;
else ans[i]=1;
}
}
// cout<<"FAFAF\n";
int Ans=0;
for(int i=30;i>=0;--i){
// cout<<ans[i]<<'\n';
Ans=Ans+(ans[i]<<i);
}
cout<<"! "<<Ans<<'\n';
cout.flush();
}
int main(){
// n=read();m=read();
std::ios::sync_with_stdio(false);
// cin.tie(0);
cin>>n>>m;
// cout<<n<<' '<<m<<'\n';
for(int i=1;i<=n;++i){
cin>>a[i];
Insert(i);
}
// cout<<"AFA\n";
dfs(rt);
// cout<<"FAF\n";
for(int i=1;i<=m;++i){
Solve();
}
cout.flush();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 15848kb
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: 1ms
memory: 15904kb
input:
1 1 0
output:
! 0
result:
ok 1 number(s): "0"
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 15848kb
input:
10 10 380864879 387438357 21484978 21099484 375657510 23189485 24467021 379687119 386094773 15156199 1 10 -1 7 3 10 1 5 4 2 7 4 -1 3 10 -1 3 10 4 3 6 2 7 4 8 2 4 9 3 8
output:
? 5 ? 9 ? 3 ! 4 ? 5 ? 4 ? 3 ! 3 ? 5 ? 9 ? 3 ! 0 ? 5 ? 4 ? 3 ! 3 ? 5 ? 4 ? 3 ! 3 ? 5 ? 4 ? 3 ! 3 ? 5 ? 4 ? 3 ! 3 ? 5 ? 4 ? 3 ! 3 ? 5 ? 9 ? 3 ! 2 ? 5 ? 4 ? 3 ! 3
result:
wrong answer 1st numbers differ - expected: '271581184', found: '4'