QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#599680#9351. Game StoreMacesutedWA 0ms3860kbC++231.9kb2024-09-29 08:56:482024-09-29 08:56:49

Judging History

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

  • [2024-09-29 08:56:49]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3860kb
  • [2024-09-29 08:56:48]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#define endl '\n'

const int N = 1e6 + 10;
int n;
vector<pair<int, __int128_t>> vec;
// __int128_t
__int128_t p[N];
__int128_t base2, base3;
int ans;

int getbit(__int128_t &x, int i) { return x >> (2 * i) & 3; }

__int128_t Xor(__int128_t &a, __int128_t &b) {
    __int128 v2 = (a & b & base2), v3 = ((a | b) & base3);
    return a + b - 3 * ((v2 >> 1) | ((v3 >> 1) & v3));
}

int insert(__int128_t x) {
    for (int i = 59; ~i; --i) {
        if (getbit(x, i) != 0) {
            if (!p[i]) {
                p[i] = x;
                return 1;
            } else {
                x = Xor(x, p[i]);
                if (getbit(x, i) != 0) x = Xor(x, p[i]);
            }
        }
    }
    return 0;
}

bool cmp(pair<int, __int128_t> a, pair<int, __int128_t> b) { return a.first > b.first; }

__int128_t btot(int x) {
    __int128_t res = 0;
    for (int i = 0; i < 60; ++i) {
        if (x >> i & 1) {
            res |= (__int128_t)1 << (2 * i);
        }
    }
    return res;
}

void rebuild() {
    sort(vec.begin(), vec.end(), cmp);
    vector<pair<int, __int128_t>> res;
    ans = 0;
    // clear();
    for (int i = 59; ~i; --i) p[i] = 0;
    for (auto it : vec) {
        if (insert(it.second)) {
            ans += it.first;
            res.emplace_back(it.first, it.second);
        }
    }
    vec = res;
}

int main() {
    ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);

    for (int i = 0; i + 1 < 120; i += 2) base2 |= (__int128_t)1 << (2 * i + 1), base3 |= (__int128_t)3 << (2 * i);

    cin >> n;
    for (int i = 1; i <= n; ++i) {
        int x, y;
        cin >> x >> y;
        x = x ^ ans;
        int b = y ^ ans;
        __int128_t a = btot(x);
        vec.push_back(make_pair(b, a));
        rebuild();
        cout << ans << endl;
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3
1 4
6 7
4 13

output:

4
7
17

result:

wrong answer 3rd lines differ - expected: '14', found: '17'