QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#455022 | #8719. 后继 | Andyqian7 | WA | 2ms | 9748kb | C++14 | 2.2kb | 2024-06-25 17:49:08 | 2024-06-25 17:49:09 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int MAX = 4e5 + 10;
int nxt[MAX << 5][2], top, n, m, a[MAX], tag[MAX << 5][2], dep[MAX << 5], x;
bitset<MAX> tp;
vector<int> v[31];
void build()
{
for (int i = 1; i <= n; i++)
{
int cur = 0;
for (int j = 0; j < 30; j++)
{
if (!nxt[cur][a[i] >> j & 1])
{
nxt[cur][a[i] >> j & 1] = ++top;
dep[top] = dep[cur] + 1;
tp[top] = a[i] >> j & 1;
}
cur = nxt[cur][a[i] >> j & 1];
}
tag[cur][0] = tag[cur][1] = i;
}
for (int i = 0; i <= top; i++)
{
v[dep[i]].push_back(i);
}
}
int query(int p)
{
cout << "? " << p << endl;
cout.flush();
int q;
cin >> q;
return q;
}
int main()
{
cin >> n >> m;
for (int i = 1; i <= n; i++)
{
cin >> a[i];
int tmp = 0;
for (int j = 0; j < 30; j++)
{
tmp |= (a[i] >> j & 1) << (29 - j);
}
a[i] = tmp;
}
build();
while (m--)
{
x = 0;
for (int i = 29; ~i; i--)
{
for (int j : v[i])
{
if (nxt[j][0] && nxt[j][1])
{
int l = nxt[j][0], r = nxt[j][1];
if (query(tag[l][1]) != tag[r][0])
{
x |= 1 << (29 - i);
}
break;
}
}
for (int j : v[i])
{
for (int k = 0; k < 2; k++)
{
if (nxt[j][k])
{
tag[j][0] = tag[nxt[j][k]][0];
tag[j][1] = tag[nxt[j][k]][1];
}
}
if (nxt[j][0] && nxt[j][1])
{
for (int k = 0; k < 2; k++)
{
tag[j][k] = tag[nxt[j][k ^ (x >> (29 - i) & 1)]][k];
}
}
}
}
cout << x << endl;
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 2ms
memory: 9748kb
input:
5 1 1 2 3 4 5 1 5 5 -2
output:
? 2 ? 1 ? 1 3
result:
wrong answer 1st numbers differ - expected: '3', found: '-114514'