QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#571702#9351. Game Storereal_sigma_teamRE 0ms3736kbC++171.9kb2024-09-18 04:17:292024-09-18 04:17:29

Judging History

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

  • [2024-09-18 04:17:29]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:3736kb
  • [2024-09-18 04:17:29]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

void solve();

int32_t main() {
#ifndef LOCAL
    cin.tie(nullptr)->sync_with_stdio(false);
#endif
    int t = 1;
    // cin >> t;
    while (t--) {
        solve();
    }
}

pair<ll, ll> __xor(pair<ll, ll> a, ll b) {
    pair<ll, ll> res;
    res.first |= (a.first & ~a.second) & ~b;
    res.first |= ~a.second & b;
    res.second |= (a.first & ~a.second) & b;
    res.second |= a.second & ~b;
    res.first |= res.second;
    return res;
}

pair<ll, ll> _xor(pair<ll, ll> a, pair<ll, ll> b) {
    return __xor(__xor(a, b.first), b.second);
}

using num = pair<ll, ll>;

num norm(num& x) {
    num res;
    res.first = x.first | x.second;
    res.second = x.first & x.second;
    return res;
}

void solve() {
    int n;
    cin >> n;
    ll last = 0;
    array<pair<num, ll>, 60> base;
    base.fill({{0, 0}, 0});
    for (int i = 0; i < n; i++) {
        ll x, y;
        cin >> x >> y;
        x ^= last;
        y ^= last;
        num a = {x, 0};
        ll b = y;
        pair<ll, int> mx = {0, 0};
        pair<num, int> oink;
        for (int j = 59; j >= 0; --j) {
            if (!base[j].first.first) continue;
            auto [v, c] = base[j];
            if (a.first >> j & 1) {
                if (make_pair(b - c, j) > mx) {
                    mx = make_pair(b - c, j);
                    oink = {a, b};
                }
                while (a.first >> j & 1) {
                    a = _xor(a, v);
                }
            } else {
                break;
            }
        }
        if (a.first) {
            base[63 - __builtin_clzll(a.first)] = {a, b};
            last += b;
        } else if (mx.first > 0) {
            last += mx.first;
            base[mx.second] = oink;
        }
        cout << last << '\n';
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3
1 4
6 7
4 13

output:

4
7
14

result:

ok 3 lines

Test #2:

score: -100
Runtime Error

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: