QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#417168#8719. 后继yzhangAC ✓536ms66768kbC++141.7kb2024-05-22 15:39:152024-05-22 15:39:15

Judging History

你现在查看的是最新测评结果

  • [2024-05-22 15:39:15]
  • 评测
  • 测评结果:AC
  • 用时:536ms
  • 内存:66768kb
  • [2024-05-22 15:39:15]
  • 提交

answer

#include<bits/stdc++.h>
#define N 400005
using namespace std;
int n,m,a[N],b[N];
int tr[N*32][2],v[N*32],cnt,rt;
int vis[35];
void insert(int &x,int val,int dep,int id){
    if(!x) x=++cnt;
    if(dep==-1){v[x]=id;return;}
    if(val&(1<<dep)) insert(tr[x][1],val,dep-1,id);
    else insert(tr[x][0],val,dep-1,id);
    if(tr[x][0]&&tr[x][1]&&vis[dep]==0) vis[dep]=x;
}
int ans;
int qry(int x,int dep){
    if(dep==-1) return v[x];
    int mx=1^((ans>>dep)&1);
    if(tr[x][mx]) return qry(tr[x][mx],dep-1);
    else return qry(tr[x][mx^1],dep-1);
}
void sol(){
    cin>>n>>m;
    for(int i=1;i<=n;++i){
        cin>>a[i];
        // b[i]=i;
        insert(rt,a[i],29,i);
    }
    // for(int i=0;i<=3;++i) cerr<<vis[i]<<endl;
    // sort(b+1,b+1+n,[](int x,int y){return a[x]<a[y];});
    for(int t=1;t<=m;++t){
        ans=0;
        for(int i=0;i<=29;++i){
            if(vis[i]){
                int p=qry(tr[vis[i]][0],i-1);
                cout<<"? "<<p<<endl;
                cout.flush();
                int val=0;
                cin>>val;
                if(val==-1){
                    ans^=(1<<i);
                }else{
                    int tmp=a[p]^a[val];
                    // cerr<<p<<" "<<val<<" "<<tmp;
                    bool fl=0;
                    for(int j=29;j>i;--j) 
                        if(tmp&(1<<j))
                            fl=1;
                    if((a[val]&(1<<i))==0)
                        fl=1;
                    if(fl) ans^=(1<<i);
                }
            }
            // cerr<<"ans "<<ans<<endl;
            // cerr.flush();
        }
        cout<<"! "<<ans<<endl;
        cout.flush();
    }
}   
int main(){
    sol();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3668kb

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: 3668kb

input:

1 1
0

output:

! 0

result:

ok 1 number(s): "0"

Test #3:

score: 0
Accepted
time: 0ms
memory: 5684kb

input:

10 10
380864879 387438357 21484978 21099484 375657510 23189485 24467021 379687119 386094773 15156199
3
4
-1
1
2
-1
3
4
10
7
7
-1
7
10
7
1
3
-1
7
-1
7
2
2
-1
3
4
10
-1
-1
2
3
4
10
-1
-1
2
3
7
6
4
4
-1
7
-1
7
2
2
-1
6
7
6
8
9
-1
3
7
8
9
9
8

output:

? 4
? 6
? 3
? 5
? 8
? 3
! 271581184
? 4
? 6
? 3
? 5
? 5
? 10
! 296747008
? 4
? 6
? 4
? 5
? 8
? 10
! 286523392
? 4
? 6
? 4
? 5
? 5
? 6
! 278134784
? 4
? 6
? 3
? 5
? 5
? 10
! 28311552
? 4
? 6
? 3
? 5
? 5
? 10
! 28311552
? 4
? 6
? 3
? 5
? 5
? 10
! 293601280
? 4
? 6
? 4
? 5
? 5
? 6
! 278134784
? 4
? 6
?...

result:

ok 10 numbers

Test #4:

score: 0
Accepted
time: 59ms
memory: 5724kb

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
? 26
? 27
? 17
? 17
? 7
? 72
? 78
? 19
? 44
? 41
! 184027136
? 11
? 58
? 88
? 26
? 27
? 17
? 17
? 7
? 4
? 78
? 55
? 44
? 55
! 445644800
? 11
? 58
? 88
? 26
? 27
? 17
? 24
? 28
? 81
? 78
? 57
? 92
? 70
! 145555456
? 11
? 58
? 88
? 26
? 27
? 17
? 17
? 7
? 30
? 78
? 77
? 44
? 41
! 179914...

result:

ok 3000 numbers

Test #5:

score: 0
Accepted
time: 536ms
memory: 66768kb

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:

? 65503
? 24195
? 14712
? 1005
? 15989
? 5820
? 5242
? 1687
? 248
? 1598
? 1103
? 675
? 207732
? 247
? 28500
? 94348
? 329246
? 82156
? 61401
? 273471
? 252486
? 111865
? 40818
? 120318
? 198723
? 6536
? 137120
? 297218
? 297218
? 248810
! 140702791
? 65503
? 24195
? 14712
? 1005
? 15989
? 5820
? 52...

result:

ok 3000 numbers

Test #6:

score: 0
Accepted
time: 453ms
memory: 40796kb

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:

? 1487
? 1127
? 1203
? 245855
? 211932
? 10832
? 137541
? 51
? 19950
? 271185
? 250988
? 135732
? 386535
? 383297
? 386535
? 174147
? 390588
? 179870
? 38445
? 38445
! 113099425
? 1487
? 1127
? 1203
? 663
? 275314
? 394988
? 181985
? 188038
? 337382
? 393790
? 347196
? 284174
? 10788
? 276434
? 1891...

result:

ok 3000 numbers

Extra Test:

score: 0
Extra Test Passed