QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#421255#8719. 后继hazeWA 0ms3468kbC++233.0kb2024-05-25 15:59:092024-05-25 15:59:10

Judging History

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

  • [2024-05-25 15:59:10]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3468kb
  • [2024-05-25 15:59:09]
  • 提交

answer

//
// Created by DELLPC on 24-5-19.
//
#include "bits/stdc++.h"

using namespace std;

using i64 = long long;
using i32 = unsigned int;


i32 ask(int x) {
    cout << "? " << x << endl;
    i32 res;
    cin >> res;
    return res;
}

void anw(int x) {
    cout << "! " << x << endl;
}


class Tired {
private:
    struct Node {
//        int l, r;
        int pre;
        int id;
        int ch[2];
        int val;

        Node() : pre(0), id(0), val(0) {
            ch[0] = ch[1] = 0;
        }
    };

    vector<Node> tree;
    vector<int> a;
    vector<Node *> v;
    int tot = 0;
    int ans = 0;

    void insert(int x, int id) {
        int p = 0;
        int pre = 0;
        for (int i = 30; i >= 0; i--) {
            int c = (x >> i) & 1;
//            cerr << "c: " << c << endl;

//            cerr << "pre: " << pre << endl;
            if (!tree[p].ch[c]) {
                tree[p].ch[c] = ++tot;
                tree[tot].pre = pre;
            }
            if (tree[p].ch[0] && tree[p].ch[1]) {
                if (!v[i]) {
                    v[i] = &tree[p];
                }
            }
            pre |= (c << i);

            p = tree[p].ch[c];
        }
        tree[p].id = id;
        tree[p].val = x;

    }


    pair<int, int> getmax(int x, int i) {

        if (i < 0) {
//            cerr << "x: " << x << endl;
//            cerr << "tree[x].id: " << tree[x].id << endl;
            return {tree[x].id, x};
        }
//        cerr << (ans >> i) << endl;
        if (tree[x].ch[1 & (ans >> i)]) {
            return getmax(tree[x].ch[1 & (ans >> i)], i - 1);
        } else {
            return getmax(tree[x].ch[!(1 & (ans >> i))], i - 1);
        }
    }

public:
    Tired(int n, vector<int> &aa) : tree(n * 31 + 10), a(aa), v(31) {
        for (int i = 1; i <= n; i++) {
            insert(a[i], i);
        }
    }

    void run() {
        ans = 0;
        for (int i = 0; i <= 30; i++) {
            if (v[i]) {
                auto [len, x] = getmax(v[i]->ch[0], i - 1);
                int ans1 = ask(len);
//                cerr << "ans1: " << ans1 << endl;
//                cerr << a[ans1] << " " << tree[x].pre << " " << (a[ans1] ^ tree[x].pre) << endl;

                if (ans1 == -1 || (a[ans1] ^ tree[x].pre) <= (1 << (i + 1))) {
                    ans |= 1 << i;
                }
                cerr << a[ans1] << " " << a[len] << " " << (a[ans1] ^ tree[x].pre) << " " << ans << " "<<i << endl;
                bitset<32> b( (a[ans1] ^ tree[x].pre) );
                cerr << b << endl;
                bitset<32> c(a[ans1]);
                cerr << c << endl;
                bitset<32> d(a[len]);
                cerr << d << endl;
            }
        }
        anw(ans);

    };

};

int main() {

    i64 n, m;

    cin >> n >> m;

    vector<int> a(n + 1);
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    Tired t(n, a);
    while (m--) {
        t.run();
    }
// 5 1
// 1 2 3 4 5

}


Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3468kb

input:

5 1
1 2 3 4 5
1
5
5

output:

? 2
? 1
? 1
! 4

result:

wrong answer 1st numbers differ - expected: '3', found: '4'