QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#818661 | #9878. A xor B plus C | ucup-team004 | RE | 4ms | 9396kb | C++23 | 2.0kb | 2024-12-18 03:03:32 | 2024-12-18 03:03:33 |
Judging History
answer
#include <bits/stdc++.h>
using i64 = long long;
using u64 = unsigned long long;
using u32 = unsigned;
using u128 = unsigned __int128;
constexpr u32 P = 998244353;
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int A, B, C;
i64 N;
std::cin >> A >> B >> C >> N;
if (N == 1) {
std::cout << A << "\n";
return 0;
}
if (N == 2) {
std::cout << B << "\n";
return 0;
}
N -= 3;
constexpr int m = 20;
std::vector<i64> I;
i64 period = 3 << (m - 1);
std::vector<int> a(period);
for (int i = 0; i < period; i++) {
a[i] = (A ^ B) + C;
if (a[i] >= (1 << m)) {
a[i] -= (1 << m);
if (i <= N) {
I.push_back(i);
}
}
A = B;
B = a[i];
}
u32 ans = a[N % period];
u32 pw = 1 << m;
while (!I.empty()) {
{
int b = 0;
for (auto i : I) {
if (i % 3 == N % 3 || (i + 1) % 3 == N % 3) {
b ^= ((N - i) / period + 1) % 2;
}
}
ans += b * pw;
if (ans >= P) {
ans -= P;
}
pw += pw;
if (pw >= P) {
pw -= P;
}
}
std::vector<i64> nI;
int z[3] {};
for (auto i : I) {
z[i % 3] ^= 1;
}
int x[3] {};
for (auto i : I) {
int y = x[i % 3] ^ x[(i + 2) % 3];
if (y) {
nI.push_back(i);
}
y ^= z[i % 3] ^ z[(i + 2) % 3];
if (y) {
nI.push_back(i + period);
}
x[i % 3] ^= 1;
}
I = std::move(nI);
std::sort(I.begin(), I.end());
while (!I.empty() && I.back() > N) {
I.pop_back();
}
period *= 2;
}
std::cout << ans << "\n";
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 4ms
memory: 9396kb
input:
1 2 3 4
output:
7
result:
ok "7"
Test #2:
score: 0
Accepted
time: 4ms
memory: 9216kb
input:
123 456 789 123456789
output:
567982455
result:
ok "567982455"
Test #3:
score: 0
Accepted
time: 4ms
memory: 9180kb
input:
0 0 0 1000000000000000000
output:
0
result:
ok "0"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3608kb
input:
628 314 157 1
output:
628
result:
ok "628"
Test #5:
score: 0
Accepted
time: 0ms
memory: 3484kb
input:
167 924 167 2
output:
924
result:
ok "924"
Test #6:
score: 0
Accepted
time: 0ms
memory: 9288kb
input:
1048575 1048575 1048575 1000000000000000000
output:
1048575
result:
ok "1048575"
Test #7:
score: -100
Runtime Error
input:
287144 758614 992207 1000000000000000000