QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#479198#8719. 后继a2513472504WA 49ms5744kbC++171.5kb2024-07-15 15:53:112024-07-15 15:53:12

Judging History

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

  • [2024-07-15 15:53:12]
  • 评测
  • 测评结果:WA
  • 用时:49ms
  • 内存:5744kb
  • [2024-07-15 15:53:11]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ull = unsigned long long;
using pis = pair<ll,ll>;

const int N = 4e5+200;
const ll inf=1e9;
const ll mod=998244353;
const ll k=15;

int nxt[N*30][2],val[N*30],a[N],n,m,tot,node[31],bit[31],p[N];

int ask(int x){
    cout<<"? "<<x<<endl;
    int ret;
    cin>>ret;
    return ret;
}

void ins(int x){
    int now=0;
    for(int i=29;i>=0;i--){
        int bit=(a[x]>>i)&1;
        if(!nxt[now][bit])nxt[now][bit]=++tot;
        if(nxt[now][0]&&nxt[now][1])node[i]=now;
        now=nxt[now][bit];
    }
    val[now]=x;
}


int getid(int now,int h,int need){
    if(!nxt[now][0]&&!nxt[now][1])return now;
    int tmp=0;
    if(bit[h])tmp=1;
    if(nxt[now][need^tmp])return getid(nxt[now][need^tmp],h-1,need);
    return getid(nxt[now][need^tmp^1],h-1,need);
}

void work(){
    for(int i=0;i<30;i++)bit[i]=0;
    for(int i=0;i<30;i++){
        if(!node[i])continue;
        int now=node[i];
        int id1=getid(nxt[now][0],i-1,1),id2=getid(nxt[now][1],i-1,0);
        ll ret=ask(val[id1]);
        if(ret!=val[id2])bit[i]=1;
    }
    ll ans=0;
    for(int i=0;i<=29;i++)ans+=(1ll<<i)*bit[i];
    cout<<"! "<<ans<<endl;
    cout.flush();
}

void solve(){
    cin>>n>>m;
    for(int i=1;i<=n;i++)cin>>a[i],ins(i);
    for(int i=1;i<=m;i++)work();
}

signed main(){

    int t = 1;
    // cin>>t;
    while (t--)
    {
        solve();
    }
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

input:

1 1
0

output:

! 0

result:

ok 1 number(s): "0"

Test #3:

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

input:

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

output:

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

result:

ok 10 numbers

Test #4:

score: -100
Wrong Answer
time: 49ms
memory: 5688kb

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
? 86
? 87
? 62
? 99
? 37
? 37
? 65
? 65
? 44
! 184027136
? 11
? 85
? 88
? 86
? 87
? 62
? 99
? 60
? 100
? 32
? 32
? 44
! 445644800
? 11
? 85
? 88
? 86
? 87
? 62
? 99
? 37
? 99
? 65
? 99
? 92
! 145555456
? 11
? 85
? 88
? 86
? 87
? 62
? 99
? 37
? 99
? 65
? 65
? 44
! 179914752
? 11
? 85
?...

result:

wrong answer 5th numbers differ - expected: '543703040', found: '6832128'