QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#859547 | #9878. A xor B plus C | ucup-team6275 | TL | 9ms | 15716kb | C++23 | 2.7kb | 2025-01-17 20:38:17 | 2025-01-17 20:38:19 |
Judging History
answer
#include <bits/stdc++.h>
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 = 5e18;
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 (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
*/
詳細信息
Test #1:
score: 100
Accepted
time: 9ms
memory: 15716kb
input:
1 2 3 4
output:
7
result:
ok "7"
Test #2:
score: 0
Accepted
time: 9ms
memory: 15668kb
input:
123 456 789 123456789
output:
567982455
result:
ok "567982455"
Test #3:
score: 0
Accepted
time: 9ms
memory: 15716kb
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: 3456kb
input:
167 924 167 2
output:
924
result:
ok "924"
Test #6:
score: 0
Accepted
time: 9ms
memory: 15716kb
input:
1048575 1048575 1048575 1000000000000000000
output:
1048575
result:
ok "1048575"
Test #7:
score: -100
Time Limit Exceeded
input:
287144 758614 992207 1000000000000000000