QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#599677#9351. Game StoreMacesutedTL 0ms4104kbC++232.0kb2024-09-29 08:54:092024-09-29 08:54:09

Judging History

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

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

answer

#include <bits/stdc++.h>
#define int long long
// #define B 180
using namespace std;

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) {
    int res = 0;
    res += x >> (2 * i) & 1;
    res += 2 * (x >> (2 * i + 1) & 1);
    return res;
}

__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;
}

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

    scanf("%lld", &n);
    for (int i = 1; i <= n; ++i) {
        int x, y;
        scanf("%lld%lld", &x, &y);
        x = x ^ ans;
        int b = y ^ ans;
        __int128_t a = btot(x);
        vec.push_back(make_pair(b, a));
        rebuild();
        printf("%lld\n", ans);
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: