QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#418936 | #8719. 后继 | mrsuns | WA | 1ms | 3540kb | C++20 | 2.6kb | 2024-05-23 16:34:41 | 2024-05-23 16:34:41 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long
//#define endl '\n'
void Prework() {
}
void Solve() {
int n, m;cin >> n >> m;
vector<array<int, 2>> a(n + 1);for (int i = 1;i <= n;i++) cin >> a[i][0], a[i][1] = i;
sort(a.begin() + 1, a.end());
//vector<vector<array<int, 3>>> cun(30);
int qry;
auto query = [&](int p) {
cout << "? " << p << endl;
cin >> qry;
};
vector<array<int, 3>> cun(30);
for (int i = 0;i < 30;i++) cun[i] = { 0,0,0 };
for (int i = 1;i <= n;i++) {
if (i == 1 || i == n) {
if (i == 1) {
int v = a[i][0], w = a[i + 1][1];
int r = __lg(v ^ w);
//cun[r].push_back({ -1,r,i });
cun[r] = { -1,r,i };
}
else {
int u = a[i - 1][0], v = a[i][0];
int l = __lg(u ^ v);
//cun[l].push_back({ l,-1,i });
cun[l] = { l,-1,i };
}
}
else {
int u = a[i - 1][0], v = a[i][0], w = a[i + 1][1];
int l = __lg(u ^ v), r = __lg(v ^ w);
// if (l > r) cun[l].push_back({ l,r,i });
// else cun[r].push_back({ l,r,i });
if (l > r) cun[l] = { l,r,i };
else cun[r] = { l,r,i };
}
}
while (m--) {
int res = 0;
for (int bit = 29;bit >= 0;bit--) {
if (cun[bit] == array<int, 3>{ 0, 0, 0 }) continue;
else {
auto [l, r, i] = cun[bit];
query(i);
if (i == 1) {
if (qry == -1) {
res |= 1 << bit;
}
else {
void();
}
}
else if (i == n) {
if (qry == a[i - 1][1]) {
res |= 1 << bit;
}
else {
void();
}
}
else {
int u = a[i - 1][0], v = a[i][0], w = a[i + 1][1];
if (qry == a[i - 1][1]) {
res |= 1 << bit;
}
else {
void();
}
}
}
}
cout << "! " << res << endl;
}
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
int T = 1;
//cin >> T;
Prework();
while (T--) Solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3508kb
input:
5 1 1 2 3 4 5 -1 1 4
output:
? 4 ? 2 ? 5 ! 3
result:
ok 1 number(s): "3"
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3540kb
input:
1 1 0 -1
output:
? 1 ! 512
result:
wrong answer 1st numbers differ - expected: '0', found: '512'