QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#418939#8719. 后继mrsunsWA 1ms3664kbC++202.7kb2024-05-23 16:36:532024-05-23 16:36:53

Judging History

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

  • [2024-05-23 16:36:53]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3664kb
  • [2024-05-23 16:36:53]
  • 提交

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--) {
        if (n == 1) {
            cout << 0 << endl;
            continue;
        }
        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: 0ms
memory: 3664kb

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: 1ms
memory: 3476kb

input:

1 1
0
-2

output:

0

result:

wrong answer 1st numbers differ - expected: '0', found: '-114514'