QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#859573#9878. A xor B plus Cucup-team6275AC ✓1373ms59932kbC++232.9kb2025-01-17 20:49:552025-01-17 20:52:11

Judging History

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

  • [2025-01-17 20:52:11]
  • 评测
  • 测评结果:AC
  • 用时:1373ms
  • 内存:59932kb
  • [2025-01-17 20:49:55]
  • 提交

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 and pos < len + t) {
                    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

*/

这程序好像有点Bug,我给组数据试试?

詳細信息

Test #1:

score: 100
Accepted
time: 9ms
memory: 15720kb

input:

1 2 3 4

output:

7

result:

ok "7"

Test #2:

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

input:

123 456 789 123456789

output:

567982455

result:

ok "567982455"

Test #3:

score: 0
Accepted
time: 8ms
memory: 15712kb

input:

0 0 0 1000000000000000000

output:

0

result:

ok "0"

Test #4:

score: 0
Accepted
time: 0ms
memory: 3712kb

input:

628 314 157 1

output:

628

result:

ok "628"

Test #5:

score: 0
Accepted
time: 0ms
memory: 3712kb

input:

167 924 167 2

output:

924

result:

ok "924"

Test #6:

score: 0
Accepted
time: 7ms
memory: 15716kb

input:

1048575 1048575 1048575 1000000000000000000

output:

1048575

result:

ok "1048575"

Test #7:

score: 0
Accepted
time: 1362ms
memory: 59448kb

input:

287144 758614 992207 1000000000000000000

output:

638555367

result:

ok "638555367"

Test #8:

score: 0
Accepted
time: 1306ms
memory: 55928kb

input:

442510 534717 936857 1000000000000000000

output:

125005501

result:

ok "125005501"

Test #9:

score: 0
Accepted
time: 1373ms
memory: 56672kb

input:

507590 985947 1025549 999999999999999833

output:

363289377

result:

ok "363289377"

Test #10:

score: 0
Accepted
time: 1373ms
memory: 59932kb

input:

989414 986755 1024915 1000000000000000000

output:

176552525

result:

ok "176552525"

Test #11:

score: 0
Accepted
time: 1076ms
memory: 53384kb

input:

773910 981383 748815 999999999999999372

output:

712048477

result:

ok "712048477"

Test #12:

score: 0
Accepted
time: 707ms
memory: 39296kb

input:

539000 982202 549877 1000000000000000000

output:

49295427

result:

ok "49295427"

Test #13:

score: 0
Accepted
time: 1022ms
memory: 53496kb

input:

930318 901108 790115 999999999999999002

output:

446688556

result:

ok "446688556"

Test #14:

score: 0
Accepted
time: 1357ms
memory: 56284kb

input:

57298 210381 985237 1000000000000000000

output:

533555472

result:

ok "533555472"

Test #15:

score: 0
Accepted
time: 349ms
memory: 28012kb

input:

567956 1013479 284068 1000000000000000000

output:

13855344

result:

ok "13855344"

Test #16:

score: 0
Accepted
time: 1341ms
memory: 58408kb

input:

694266 795841 967344 1000000000000000000

output:

179712105

result:

ok "179712105"

Test #17:

score: 0
Accepted
time: 340ms
memory: 28004kb

input:

744515 402386 261828 1000000000000000000

output:

915814204

result:

ok "915814204"

Test #18:

score: 0
Accepted
time: 138ms
memory: 21864kb

input:

630928 108751 103226 1000000000000000000

output:

314920156

result:

ok "314920156"

Test #19:

score: 0
Accepted
time: 792ms
memory: 39844kb

input:

408870 219543 576432 1000000000000000000

output:

332612604

result:

ok "332612604"

Test #20:

score: 0
Accepted
time: 1355ms
memory: 57920kb

input:

208613 769277 1010542 819875140559301752

output:

110220300

result:

ok "110220300"

Test #21:

score: 0
Accepted
time: 529ms
memory: 36200kb

input:

123844 719656 377241 520974001002628387

output:

986512272

result:

ok "986512272"

Test #22:

score: 0
Accepted
time: 1179ms
memory: 55400kb

input:

774205 820111 841396 711066335916901718

output:

254873758

result:

ok "254873758"

Test #23:

score: 0
Accepted
time: 1331ms
memory: 55832kb

input:

604531 395365 966071 999594448264125858

output:

505142123

result:

ok "505142123"

Test #24:

score: 0
Accepted
time: 1268ms
memory: 56632kb

input:

59523 598376 922420 752304351201620672

output:

351022203

result:

ok "351022203"

Test #25:

score: 0
Accepted
time: 1297ms
memory: 59496kb

input:

192450 176925 1037973 192583019203393748

output:

56600397

result:

ok "56600397"

Test #26:

score: 0
Accepted
time: 1322ms
memory: 58740kb

input:

972801 523798 994144 594688603126478507

output:

750534499

result:

ok "750534499"

Test #27:

score: 0
Accepted
time: 7ms
memory: 15720kb

input:

669131 939565 629 543390474884493567

output:

652889135

result:

ok "652889135"

Test #28:

score: 0
Accepted
time: 490ms
memory: 36132kb

input:

829091 688584 371532 935387048229453232

output:

784327643

result:

ok "784327643"

Test #29:

score: 0
Accepted
time: 193ms
memory: 21860kb

input:

407113 311573 150840 428344291461283594

output:

486756568

result:

ok "486756568"

Test #30:

score: 0
Accepted
time: 346ms
memory: 28008kb

input:

338931 949581 280744 289664704872449795

output:

459928211

result:

ok "459928211"

Test #31:

score: 0
Accepted
time: 569ms
memory: 40372kb

input:

16277 434162 426083 575309380820099707

output:

927534514

result:

ok "927534514"

Test #32:

score: 0
Accepted
time: 691ms
memory: 39808kb

input:

669467 627218 559817 371026815047584891

output:

393999810

result:

ok "393999810"

Test #33:

score: 0
Accepted
time: 309ms
memory: 28012kb

input:

256940 648067 248598 702551234623621497

output:

107167397

result:

ok "107167397"

Test #34:

score: 0
Accepted
time: 116ms
memory: 25792kb

input:

112359 956967 160416 704822623170226832

output:

945781095

result:

ok "945781095"

Test #35:

score: 0
Accepted
time: 1249ms
memory: 56472kb

input:

608294 272679 879126 922348606336628938

output:

508826865

result:

ok "508826865"

Test #36:

score: 0
Accepted
time: 455ms
memory: 37268kb

input:

844223 856121 402112 640219260480538711

output:

494733011

result:

ok "494733011"

Test #37:

score: 0
Accepted
time: 113ms
memory: 18652kb

input:

589375 991964 85955 471255438930064341

output:

591777452

result:

ok "591777452"

Test #38:

score: 0
Accepted
time: 634ms
memory: 38460kb

input:

613807 685977 493404 774205724944088968

output:

686401274

result:

ok "686401274"

Test #39:

score: 0
Accepted
time: 74ms
memory: 17764kb

input:

686801 458561 52258 593361261434725536

output:

197205169

result:

ok "197205169"

Extra Test:

score: 0
Extra Test Passed