QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#602976 | #8719. 后继 | UESTC_Snow_Halation# | WA | 51ms | 11856kb | C++14 | 1.9kb | 2024-10-01 13:52:19 | 2024-10-01 13:52:21 |
Judging History
answer
#include <bits/stdc++.h>
#define ll long long
#define ls son[x][0]
#define rs son[x][1]
using namespace std;
const ll N=801010;
const ll qwq=N*32;
inline ll read() {
ll sum = 0, ff = 1; char c = getchar();
while(c<'0' || c>'9') { if(c=='-') ff = -1; c = getchar(); }
while(c>='0'&&c<='9') { sum = sum * 10 + c - '0'; c = getchar(); }
return sum * ff;
}
ll n,m;
ll a[N];
ll son[qwq][2],tot,dep[qwq];
ll id[qwq];
ll xiong1[N],xiong2[N];
inline ll ask(ll cl,ll x,ll now,ll k) { // 1 : max
// cout<<"cl = "<<cl<<" x = "<<x<<" k = "<<k<<"\n";
for(;k>=0;k--) {
ll c = (now>>k)&1;
if(cl==1) {
if(son[x][c^1]) x = son[x][c^1];
else x = son[x][c];
}
else {
if(son[x][c]) x = son[x][c];
else x = son[x][c^1];
}
}
// cout<<"id = "<<id[x]<<"\n";
return id[x];
}
int main() {
n = read(); m = read();
for(ll i=1;i<=n;i++) {
a[i] = read();
ll now = 0;
for(ll k=29;k>=0;k--) {
ll c = (a[i]>>k)&1;
if(!son[now][c]) son[now][c] = ++tot, dep[tot] = k;
now = son[now][c];
}
id[now] = i;
}
for(ll i=0;i<=tot;i++) {
if(son[i][0] && son[i][1]) {
xiong1[ dep[i]-1 ] = son[i][0], xiong2[ dep[i]-1 ] = son[i][1];
}
}
while(m--) {
ll now = 0;
for(ll k=0;k<=29;k++) {
if(!xiong1[k]) continue;
// cout<<xiong1[k]<<" "<<xiong2[k]<<" k = "<<k<<endl;
ll A = ask(1,xiong1[k],now,k-1);
ll B = ask(0,xiong2[k],now,k-1);
if(A<=0 || A>n) {
while(1) {
now++;
}
}
cout<<"? "<<A<<"\n";
fflush(stdout);
ll C = read();
if(C!=B) now |= (1ll<<k);
}
cout<<"! "<<now<<"\n";
fflush(stdout);
}
return 0;
}
/*
31 1
0 1 2 4 8 16 32 64 128 256
512 1024 2048 4096 8192 16384 32768 65536 131072 262144
524288 1048576 2097152 4194304 8388608 16777216 33554432 67108864 134217728 268435456 536870912
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 11744kb
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: 2ms
memory: 9780kb
input:
1 1 0
output:
! 0
result:
ok 1 number(s): "0"
Test #3:
score: 0
Accepted
time: 3ms
memory: 11800kb
input:
10 10 380864879 387438357 21484978 21099484 375657510 23189485 24467021 379687119 386094773 15156199 3 4 -1 1 7 -1 3 4 10 7 -1 -1 7 10 7 1 -1 -1 7 -1 7 2 3 -1 3 4 10 -1 2 2 3 4 10 -1 2 2 3 7 6 4 -1 -1 7 -1 7 2 3 -1 6 7 6 8 3 -1 3 7 8 9 6 8
output:
? 4 ? 6 ? 3 ? 5 ? 10 ? 3 ! 271581184 ? 4 ? 6 ? 3 ? 5 ? 10 ? 10 ! 296747008 ? 4 ? 6 ? 4 ? 5 ? 10 ? 10 ! 286523392 ? 4 ? 6 ? 4 ? 5 ? 10 ? 6 ! 278134784 ? 4 ? 6 ? 3 ? 5 ? 10 ? 10 ! 28311552 ? 4 ? 6 ? 3 ? 5 ? 10 ? 10 ! 28311552 ? 4 ? 6 ? 3 ? 5 ? 10 ? 10 ! 293601280 ? 4 ? 6 ? 4 ? 5 ? 10 ? 6 ! 278134784 ?...
result:
ok 10 numbers
Test #4:
score: -100
Wrong Answer
time: 51ms
memory: 11856kb
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 ? 58 ? 88 ? 86 ? 75 ? 62 ? 99 ? 51 ? 65 ? 41 ? 19 ? 44 ! 184027136 ? 11 ? 58 ? 88 ? 86 ? 75 ? 62 ? 99 ? 51 ? 32 ? 41 ? 55 ? 44 ! 445644800 ? 11 ? 58 ? 88 ? 86 ? 75 ? 62 ? 99 ? 51 ? 65 ? 41 ? 57 ? 92 ! 145555456 ? 11 ? 58 ? 88 ? 86 ? 75 ? 62 ? 99 ? 51 ? 65 ? 41 ? 77 ? 44 ! 179914752 ? 11 ? 58 ? ...
result:
wrong answer 5th numbers differ - expected: '543703040', found: '6832128'