QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#599704#9351. Game StoreMacesutedTL 0ms3512kbC++232.0kb2024-09-29 09:22:242024-09-29 09:22:25

Judging History

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

  • [2024-09-29 09:22:25]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:3512kb
  • [2024-09-29 09:22:24]
  • 提交

answer

/**
 * @file 9351.cpp
 * @author Macesuted ([email protected])
 * @date 2024-09-29
 *
 * @copyright Copyright (c) 2024
 *
 */

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

#ifndef LOCAL
#define endl '\n'
#endif

bool mem1;

#define maxlgn 60

typedef __int128_t int128_t;
typedef pair<int64_t, int128_t> plL;

int128_t base1, base2, base[maxlgn];

vector<plL> vec;

int128_t xor3(int128_t a, int128_t b) {
    return a + b - 3 * (((a & b & base2) >> 1) | ((((a | b) & base2) >> 1) & ((a | b) & base1)));
}

void solve(void) {
    int n;
    cin >> n;

    int64_t ans = 0;
    vec.clear();
    for (int i = 1; i <= n; i++) {
        int64_t x, y;
        cin >> x >> y, x ^= ans, y ^= ans;

        vec.emplace_back(y, [&](int64_t x) {
            int128_t ans = 0;
            for (int i = 0; i < maxlgn; i++) ans |= int128_t(x >> i & 1) << (i * 2);
            return ans;
        }(x));
        sort(vec.begin(), vec.end(), greater<plL>());

        vector<plL> tmp;
        for (int i = 0; i < maxlgn; i++) base[i] = 0;
        ans = 0;
        for (auto [w, v] : vec) {
            plL val = {w, v};
            for (int i = 0; i < maxlgn; i++) {
                if (!(v >> (2 * i) & 3)) continue;
                if (!base[i]) {
                    base[i] = v, ans += w, tmp.push_back(val);
                    break;
                }
                while (v >> (2 * i) & 3) v = xor3(v, base[i]);
            }
        }
        vec = tmp;

        cout << ans << endl;
    }
    return;
}

bool mem2;

int main() {
    ios::sync_with_stdio(false), cin.tie(nullptr);
#ifdef LOCAL
    cerr << "Memory Cost: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl;
#endif

    for (int i = 0; i < maxlgn; i++) base1 |= (int128_t)1 << (i * 2), base2 |= (int128_t)2 << (i * 2);

    int _ = 1;
    while (_--) solve();

#ifdef LOCAL
    cerr << "Time Cost: " << clock() * 1000. / CLOCKS_PER_SEC << "MS" << endl;
#endif
    return 0;
}

详细

Test #1:

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

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: