QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#469283 | #8719. 后继 | JEdward | WA | 1ms | 7780kb | C++17 | 1.7kb | 2024-07-09 17:02:42 | 2024-07-09 17:02:42 |
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, dep[p] = i;
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: 100
Accepted
time: 1ms
memory: 7780kb
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: 7696kb
input:
1 1 0
output:
! 0
result:
ok 1 number(s): "0"
Test #3:
score: -100
Wrong Answer
time: 1ms
memory: 7760kb
input:
10 10 380864879 387438357 21484978 21099484 375657510 23189485 24467021 379687119 386094773 15156199 3 4
output:
? 4 ? 6 ? 0
result:
wrong answer Answer contains longer sequence [length = 10], but output contains 0 elements