QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#603000 | #8719. 后继 | liguo# | WA | 47ms | 3912kb | C++20 | 2.3kb | 2024-10-01 14:02:28 | 2024-10-01 14:02:28 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
struct node{
int lson=0,rson=0,dep=0,ed=0,val=0;
}nd[12000006];
int cnt=0;
void add(int num,int id){
int now=0;
for(int i=29;i>=0;i--){
if(num&(1<<i)){
if(nd[now].rson==0){
nd[now].rson=++cnt;
nd[cnt].dep=i;
nd[cnt].val=nd[now].val+(1<<i);
}
now=nd[now].rson;
}
else{
if(nd[now].lson==0){
nd[now].lson=++cnt;
nd[cnt].dep=i;
nd[cnt].val=nd[now].val;
}
now=nd[now].lson;
}
}
nd[now].ed=id;
}
int x=0,a[400005];
int diff[32]={0};
int findmax(int now,int d){
if(d==0)
return now;
if(nd[now].rson==0) return findmax(nd[now].lson,d-1);
if(nd[now].lson==0) return findmax(nd[now].rson,d-1);
if((x&(1<<(d-1)))!=0){
// printf("max : %d -> %d\n",now,nd[now].lson);
return findmax(nd[now].lson,d-1);
}
else{
// printf("max : %d -> %d\n",now,nd[now].rson);
return findmax(nd[now].rson,d-1);
}
}
int findmin(int now,int d){
if(d==0)
return now;
if(nd[now].rson==0) return findmin(nd[now].lson,d-1);
if(nd[now].lson==0) return findmin(nd[now].rson,d-1);
if((x&(1<<(d-1)))!=0){
// printf("min : %d -> %d\n",now,nd[now].rson);
return findmin(nd[now].rson,d-1);
}
else{
// printf("min : %d -> %d\n",now,nd[now].lson);
return findmin(nd[now].lson,d-1);
}
}
int main(){
int n,m;scanf("%d %d",&n,&m);
for(int i=1;i<=n;i++){
scanf("%d",&a[i]);
add(a[i],i);
}
for(int i=1;i<=cnt;i++){
if(diff[nd[i].dep])
continue;
if(nd[i].lson!=0&&nd[i].rson!=0)
diff[nd[i].dep]=i;
}
for(int t=1;t<=m;t++){
x=0;
for(int i=1;i<=30;i++){
if(diff[i]==0)
continue;
int a1=findmax(nd[diff[i]].lson,i-1);
int a2=findmin(nd[diff[i]].rson,i-1);
printf("? %d\n",nd[a1].ed);
// printf("Diff : %d %d %d\n",diff[i],a1,a2);
fflush(stdout);
int res;scanf("%d",&res);
if(res!=nd[a2].ed)
x|=(1<<(i-1));
}
printf("! %d\n",x);
fflush(stdout);
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3796kb
input:
5 1 1 2 3 4 5 1 5 5
output:
? 2 ? 1 ? 1 ! 3
result:
ok 1 number(s): "3"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3788kb
input:
1 1 0
output:
! 0
result:
ok 1 number(s): "0"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3760kb
input:
10 10 380864879 387438357 21484978 21099484 375657510 23189485 24467021 379687119 386094773 15156199 3 2 -1 1 2 -1 3 5 10 7 7 -1 7 3 7 1 3 -1 7 5 7 2 2 -1 3 5 10 -1 -1 2 3 5 10 -1 -1 2 3 1 6 4 4 -1 7 5 7 2 2 -1 6 1 6 8 9 -1 3 1 8 9 9 8
output:
? 4 ? 8 ? 3 ? 5 ? 8 ? 3 ! 271581184 ? 4 ? 8 ? 3 ? 5 ? 5 ? 10 ! 296747008 ? 4 ? 8 ? 4 ? 5 ? 8 ? 10 ! 286523392 ? 4 ? 8 ? 4 ? 5 ? 5 ? 6 ! 278134784 ? 4 ? 8 ? 3 ? 5 ? 5 ? 10 ! 28311552 ? 4 ? 8 ? 3 ? 5 ? 5 ? 10 ! 28311552 ? 4 ? 8 ? 3 ? 5 ? 5 ? 10 ! 293601280 ? 4 ? 8 ? 4 ? 5 ? 5 ? 6 ! 278134784 ? 4 ? 8 ?...
result:
ok 10 numbers
Test #4:
score: -100
Wrong Answer
time: 47ms
memory: 3912kb
input:
100 3000 416322873 449728250 688705913 946343465 16202884 153238658 573284215 724198910 577719053 868106680 951494055 942341618 190594266 331719623 856324110 977865755 151782935 163752541 1565918 870244322 299691610 37854919 198293342 152446496 549402023 869857831 869628458 573984494 162791133 94423...
output:
? 11 ? 85 ? 88 ? 15 ? 47 ? 2 ? 2 ? 67 ? 78 ? 78 ? 41 ? 19 ! 184027136 ? 11 ? 85 ? 88 ? 15 ? 47 ? 2 ? 2 ? 63 ? 78 ? 78 ? 41 ? 55 ! 445644800 ? 11 ? 85 ? 88 ? 15 ? 47 ? 2 ? 88 ? 67 ? 78 ? 78 ? 70 ? 57 ! 145555456 ? 11 ? 85 ? 88 ? 15 ? 47 ? 2 ? 2 ? 67 ? 78 ? 78 ? 41 ? 77 ! 179914752 ? 11 ? 85 ? 88 ? 15...
result:
wrong answer 5th numbers differ - expected: '543703040', found: '6832128'