QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#859557#9878. A xor B plus Cucup-team6275WA 9ms15716kbC++232.8kb2025-01-17 20:44:172025-01-17 20:44:27

Judging History

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

  • [2025-01-17 20:44:27]
  • 评测
  • 测评结果:WA
  • 用时:9ms
  • 内存:15716kb
  • [2025-01-17 20:44:17]
  • 提交

answer

#pragma GCC optimize("Ofast,unroll-loops")

#include <bits/stdc++.h>

#pragma GCC target("avx,avx2,fma")

using namespace std;

using ll = long long;
using ld = long double;
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define rep(i, n) for (int i = 0; i < (n); i += 1)
#define len(a) ((int)(a).size())

mt19937 rnd(234);
const ll inf = 2e18;
const ll mod = 998244353;

ll a, b, c, n;

int32_t main() {
    if (1) {
        ios::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
    }
    cin >> a >> b >> c >> n;
    n -= 1;
    if (n == 0) {
        cout << a << "\n";
        return 0;
    }
    if (n == 1) {
        cout << b << "\n";
        return 0;
    }
    n -= 2;
    rep(itr, 2) {
        ll tmp = ((a ^ b) + c) % (1 << 20);
        a = b;
        b = tmp;
    }
    ll cycle = 3 * (1 << 19);
    vector<ll> values(cycle);
    values[0] = a;
    values[1] = b;
    vector<ll> carry;
    for (int i = 2; i < cycle; i = (i + 1) % cycle) {
        int prv = (i + cycle - 1) % cycle;
        int prvprv = (i + cycle - 2) % cycle;
        values[i] = (values[prv] ^ values[prvprv]) + c;
        if ((values[i] >> 20) & 1) {
            values[i] -= (1 << 20);
            carry.push_back(i);
        }
        assert(values[i] < (1 << 20));
        if (i == 1) {
            break;
        }
    }
    sort(all(carry));
    ll res = values[n % cycle] % mod;
    ll pwr = (1 << 20);
    ll len = (3 << 19);
    for (int bit = 20; !carry.empty(); ++bit) {
        cerr << bit << "\n";
        auto get_val = [&](ll pos) -> ll {
            pos %= 2 * len;
            ll res = 0;
            for (auto t : carry) {
                if (t % 3 == (pos + 1) % 3) {
                    continue;
                }
                if (pos >= len + t) {
                    break;
                }
                if (t <= pos) {
                    res ^= 1;
                }
            }
            return res;
        };
        if (get_val(n)) {
            res = (res + pwr) % mod;
        }
        vector<ll> new_carry;
        array<int, 3> cnt = {0, 0, 0};
        for (auto d : {0, 1}) {
            for (auto t : carry) {
                ll aboba = d * len + t;
                if (aboba > n) {
                    break;
                }
                cnt[aboba % 3] ^= 1;
                if ((cnt[aboba % 3] ^ cnt[(aboba + 2) % 3]) == 0) {
                    new_carry.push_back(aboba);
                }
                // if (get_val(aboba) == 0) {
                //     new_carry.push_back(aboba);
                // }
            }
        }
        pwr = (pwr * 2) % mod;
        len *= 2;
        len = min(len, inf);
        carry.swap(new_carry);
    }
    cout << res << "\n";
    return 0;
}

/*
11111 22222 88888

*/

详细

Test #1:

score: 100
Accepted
time: 8ms
memory: 15716kb

input:

1 2 3 4

output:

7

result:

ok "7"

Test #2:

score: -100
Wrong Answer
time: 9ms
memory: 15712kb

input:

123 456 789 123456789

output:

496679287

result:

wrong answer 1st words differ - expected: '567982455', found: '496679287'