QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#469275 | #8719. 后继 | JEdward | WA | 0ms | 5708kb | C++17 | 1.7kb | 2024-07-09 16:59:54 | 2024-07-09 16:59:54 |
Judging History
answer
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(0), cin.tie(0)
#define int long long
//#define endl '\n'
#define lowbit(x) (x)&(-x)
#define pii pair<int,int>
#define all(s) s.begin(), s.end()
#define ls(x) (x<<1)
#define rs(x) (x<<1|1)
#define here system("pause")
using namespace std;
const int N = 4e5+5;
const int mod = 1e9+7;
const int INF = 1e15+7;
const double eps = 1e-6;
inline int pow(int a, int b, int p){ int res = 1%p; while(b){ if(b&1) res=res*a%p; a=a*a%p, b>>=1;} return res;}
inline int inv(int a, int p){ return pow(a,p-2,p)%p;}
int n, m, tot;
int a[N], ch[N*31][2], dep[N*31], id[N*31];
int wh[30];//用于存储具有两个不同子节点(即0和1分支都存在)的节点的索引,如果不存在则为-1。
inline int ask(int x){
cout << "? " << x << endl;
cin >> x;
return x;
}
inline int insert(int x){
int p = 0;
for(int i=29;i>=0;i--){
int j = x>>i&1;
if(!ch[p][j]) ch[p][j] = ++tot;
p = ch[p][j];
}
return p;
}
inline void sol(){
cin >> n >> m;
for(int i=1;i<=n;i++){
cin >> a[i];
id[insert(a[i])] = i;
}
memset(wh, -1, sizeof wh);
for(int i=0;i<tot;i++){
if(ch[i][0] && ch[i][1]) wh[dep[i]] = i;
}
while(m--){
int res = 0;
for(int i=0;i<30;i++){
if(~wh[i]){
int l = ch[wh[i]][0], r = ch[wh[i]][1];
for(int j=i-1;j>=0;j--){
if(ch[l][!(res>>j)&1]) l = ch[l][!(res>>j)&1];
else l = ch[l][(res>>j)&1];
if(ch[r][(res>>j)&1]) r = ch[r][(res>>j)&1];
else r = ch[r][!(res>>j)&1];
}
if(ask(id[l])!=id[r]){
res |= 1<<i;
}
}
}
cout << "! " << res << endl;
}
}
signed main(){
IOS;
int tc = 1;
while(tc--){
sol();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 5708kb
input:
5 1 1 2 3 4 5 -1
output:
? 4 ! 1
result:
wrong answer 1st numbers differ - expected: '3', found: '1'