QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#599683#9351. Game StoreMacesutedTL 0ms3624kbC++231.9kb2024-09-29 08:59:392024-09-29 08:59:39

Judging History

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

  • [2024-09-29 08:59:39]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:3624kb
  • [2024-09-29 08:59:39]
  • 提交

answer

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

#define endl '\n'

const int N = 1e6 + 10;
int n;
vector<pair<int64_t, __int128_t>> vec;
// __int128_t
__int128_t p[N];
__int128_t base2, base3;
int64_t 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<int64_t, __int128_t> a, pair<int64_t, __int128_t> b) { return a.first > b.first; }

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

void rebuild() {
    sort(vec.begin(), vec.end(), cmp);
    vector<pair<int64_t, __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;
    return;
}

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) {
        int64_t x, y;
        cin >> x >> y;
        x = x ^ ans;
        int64_t b = y ^ ans;
        __int128_t a = btot(x);
        vec.push_back(make_pair(b, a));
        rebuild();
        cout << ans << endl;
    }

    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3624kb

input:

3
1 4
6 7
4 13

output:

4
7
14

result:

ok 3 lines

Test #2:

score: -100
Time Limit Exceeded

input:

500000
395134631858718935 964539556
125290790696511447 743741881
68785955678986648 1867726875
774218610629433714 1107843806
251011758189826329 3218789432
712376502291877860 3368474950
237512969552427655 3307057592
26026853208103063 3366794857
904189246433646740 3824475130
105677592268903953 50111856...

output:

964539556
1319559617
1889305499
2737921248
3223119288
3371639478
3605116356
4113447281
4496890876
5146597364
5443005741
5560684788
6532334449
7521134451
8336539770
8705245338
9014268525
9265374719
9381614536
9559254162
10004316290
10462314640
10662416153
10955313276
11748683855
12256749782
129943566...

result: