QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#602986 | #8719. 后继 | UESTC_Snow_Halation# | AC ✓ | 313ms | 166488kb | C++14 | 1.8kb | 2024-10-01 13:56:53 | 2024-10-01 13:56:54 |
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();
dep[0] = 30;
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);
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: 2ms
memory: 11712kb
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: 0ms
memory: 9748kb
input:
1 1 0
output:
! 0
result:
ok 1 number(s): "0"
Test #3:
score: 0
Accepted
time: 1ms
memory: 11828kb
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: 0
Accepted
time: 52ms
memory: 11728kb
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 ? 41 ! 184027136 ? 11 ? 58 ? 88 ? 86 ? 75 ? 62 ? 99 ? 51 ? 32 ? 41 ? 55 ? 44 ? 55 ! 445644800 ? 11 ? 58 ? 88 ? 86 ? 75 ? 62 ? 99 ? 51 ? 65 ? 41 ? 57 ? 92 ? 70 ! 145555456 ? 11 ? 58 ? 88 ? 86 ? 75 ? 62 ? 99 ? 51 ? 65 ? 41 ? 77 ? 44 ? 41 ! 17...
result:
ok 3000 numbers
Test #5:
score: 0
Accepted
time: 313ms
memory: 166488kb
input:
400000 3000 406697044 910508999 785308673 89872855 911511537 786066190 569035255 791369083 231783630 373589094 1005702647 785128281 910883228 612232307 428493618 691767283 288087749 380834477 1012471581 807583302 951439706 172399529 651163374 395700503 212381194 528978756 628513589 230244101 1046447...
output:
? 324118 ? 354061 ? 367950 ? 389615 ? 396724 ? 394970 ? 397048 ? 395931 ? 399726 ? 397704 ? 398644 ? 399974 ? 395304 ? 396852 ? 305853 ? 334550 ? 222082 ? 62854 ? 221815 ? 268311 ? 133345 ? 197826 ? 126445 ? 394374 ? 344544 ? 371824 ? 34497 ? 304394 ? 297218 ? 248810 ! 140702791 ? 324118 ? 354061 ? ...
result:
ok 3000 numbers
Test #6:
score: 0
Accepted
time: 275ms
memory: 99436kb
input:
400000 3000 49852143 106643027 78538081 13535110 34673790 361240760 358287062 285333122 15578697 106130051 320170693 107023555 72813915 2799162 286900401 787319 332890808 75095435 110215229 74827421 107485420 300695656 71750101 285593446 37660664 397030779 392989831 16018850 14036294 361777963 11269...
output:
? 399108 ? 399890 ? 399208 ? 389830 ? 279367 ? 294436 ? 274594 ? 139961 ? 362951 ? 214558 ? 255424 ? 3814 ? 169795 ? 251886 ? 29307 ? 37678 ? 37678 ? 386535 ? 386535 ? 38445 ! 113099425 ? 399108 ? 399890 ? 399208 ? 384877 ? 336455 ? 228542 ? 96287 ? 160598 ? 64854 ? 303272 ? 136187 ? 292072 ? 334176...
result:
ok 3000 numbers
Extra Test:
score: 0
Extra Test Passed