QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#455022#8719. 后继Andyqian7WA 2ms9748kbC++142.2kb2024-06-25 17:49:082024-06-25 17:49:09

Judging History

你现在查看的是最新测评结果

  • [2024-06-25 17:49:09]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:9748kb
  • [2024-06-25 17:49:08]
  • 提交

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'