QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#419530#8719. 后继mrsunsRE 0ms0kbC++202.1kb2024-05-24 01:23:442024-05-24 01:23:44

Judging History

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

  • [2024-05-24 01:23:44]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-05-24 01:23:44]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long 
//#define endl '\n'
const int N = 2e5 + 10;
int tr[2][N], tot = 0;
int tag[N];
void insert(int x, int p) {
    int cur = 0;
    for (int i = 0;i < 30;i++) {
        int u = x >> i & 1;
        if (!tr[u][cur]) tr[u][cur] = ++tot;
        cur = tr[u][cur];
    }
    tag[cur] = p;
}
void Prework() {

}
void Solve() {
    int n, m;cin >> n >> m;
    vector<int> a(n + 1);for (int i = 1;i <= n;i++) cin >> a[i];
    vector<array<int, 2>> a2(n + 1);for (int i = 1;i <= n;i++) a2[i][0] = a[i], a2[i][1] = i;
    sort(a2.begin() + 1, a2.end());
    for (int i = 1;i <= n;i++) {
        insert(a2[i][0], a2[i][1]);
    }
    if (n == 1) {
        while (m--) {
            cout << "! " << 0 << endl;
            continue;
        }
        return;
    }
    int qry;
    auto query = [&](int p) {
        cout << "? " << p << endl;
        cin >> qry;
        };
    vector<int> pos(n + 1);
    for (int i = 2;i <= n;i++) {
        int t = __lg(a2[i - 1][0] ^ a2[i][0]);
        if (a2[i][0] >> t & 1) {
            pos[t] = i - 1;
        }
        else {
            pos[t] = i;
        }
    }
    while (m--) {
        int res = 0;
        for (int w = 0;w < 30;w++) {
            if (pos[w]) {
                int u = pos[w], cur = 0;
                for (int i = 29;i >= w;i--) {
                    cur = tr[a[u] >> i & 1][cur];
                }
                for (int i = w - 1;i >= 0;i--) {
                    int z = res >> i & 1;
                    if (tr[z ^ 1][cur]) cur = tr[z ^ 1][cur];
                    else cur = tr[z][cur];
                }
                int to = tag[cur];
                query(to);
                if (qry == -1) res |= 1 << w;
                else {
                    int t = __lg(a[u] ^ a[qry]);
                    if (t != w) res |= 1 << w;
                }
            }
        }
        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();
}

详细

Test #1:

score: 0
Runtime Error

input:

5 1
1 2 3 4 5

output:

? 0

result: