QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#740627 | #8719. 后继 | ucup-team4352# | WA | 1ms | 5632kb | C++23 | 1.5kb | 2024-11-13 10:47:21 | 2024-11-13 10:47:21 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
using namespace std;
const int maxn=4e5+5;
int a[maxn];
int ch[maxn*32][2],tot=1;
int bit[35],t[35];
vector<int>id[35];
pii p[maxn];
int n,m;
int find(int x){
return p[lower_bound(p+1,p+n+1,(pii){x,0})-p].second;
}
bool check(int x,int p){
int loc=lower_bound(id[x].begin(),id[x].end(),p)-id[x].begin();
if(loc>=id[x].size()||id[x][loc]!=p)return 0;
return 1;
}
int query(int x){
cout<<"? "<<find(x)<<endl;
int y;
cin>>y;
return y;
}
void ins(int x){
int now=1,num=0;
for(int i=29;i>=0;i--){
int tmp=x>>i&1;
if(ch[now][tmp]==0)ch[now][tmp]=++tot;
if(ch[now][0]&&ch[now][1]){
bit[i]=now;
t[i]=num;
}
num^=tmp<<i;
now=ch[now][tmp];
}
}
int calc(int x){
int now=1,num=x;
for(int i=29;i>=0;i--){
int tmp=x>>i&1;
if(ch[now][tmp])now=ch[now][tmp];
else now=ch[now][tmp^1],num^=1<<i;
}
return num;
}
void solv(){
int x=0;
for(int i=0;i<30;i++){
if(bit[i]==0)continue;
int s=(1<<i)-1;
int num=calc(x^t[i]^s);
int q=query(num);
if(q==-1||check(i,q)==0){
x^=1<<i;
}
}
cout<<x<<endl;
}
void solve(){
cin>>n>>m;
for(int i=1;i<=n;i++){
cin>>a[i];
ins(a[i]);
p[i]={a[i],i};
}
for(int i=1;i<=n;i++){
for(int j=0;j<30;j++){
if(bit[j]==0)continue;
if((a[i]&t[j])==t[j]&&(a[i]&(1<<j))){
id[j].push_back(i);
}
}
}
sort(p+1,p+n+1);
while(m--)solv();
}
int main(){
ios::sync_with_stdio(0),cin.tie(0);
int t=1;
// cin>>t;
while(t--)solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 5632kb
input:
5 1 1 2 3 4 5 -1 5 5 -2
output:
? 4 ? 1 ? 1 3
result:
wrong answer 1st numbers differ - expected: '3', found: '-114514'