QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#820365 | #9878. A xor B plus C | HuTao | WA | 825ms | 39536kb | C++14 | 1.5kb | 2024-12-18 21:10:13 | 2024-12-18 21:10:14 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 6e6 + 5, Block = 19, P = 998244353;
int A, B, C;
LL n;
int x00[N];
int *x0 = x00 + 2;
LL y[N], yy[N];
int main()
{
scanf("%d%d%d%lld", &A, &B, &C, &n);
if(n == 1) return printf("%d\n", A), 0;
if(n == 2) return printf("%d\n", B), 0;
n -= 3;
LL T = 3 << Block;
LL ans = 0;
int m = 0;
x0[-2] = A, x0[-1] = B;
for(int i = -2; i < T - 2; i ++ )
{
x0[i + 2] = ((x0[i] ^ x0[i + 1]) + C) & ((1 << (Block + 1)) - 1);
if((x0[i] ^ x0[i + 1]) + C >= (1 << (Block + 1))) y[ ++ m] = i + 2;
}
ans = x0[n % T];
LL s = 1 << (Block + 1);
for(int i = Block + 1; i <= 78; i ++ , s = s * 2 % P)
{
int mm = 0;
x0[0] = x0[1] = x0[2] = 0;
int x = -1;
LL p = n % (T * 2);
for(int i = 1; i <= m; i ++ )
{
if(y[i] > p && x == -1) x = x0[p % 3];
if(x0[(y[i] + 1) % 3] ^= 1, !(x0[y[i] % 3] ^= 1))
yy[ ++ mm] = y[i];
}
for(int i = 1; i <= m && y[i] + T <= n; i ++ )
{
if(y[i] + T > p && x == -1) x = x0[p % 3];
if(x0[(y[i] + 1) % 3] ^= 1, !(x0[y[i] % 3] ^= 1))
yy[ ++ mm] = y[i] + T;
}
if(x == -1) x = x0[p % 3];
ans += s * x;
T = min(T * 2, n + 1);
m = mm;
for(int i = 1; i <= m; i ++ ) y[i] = yy[i];
}
printf("%lld\n", ans % P);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 6ms
memory: 14148kb
input:
1 2 3 4
output:
7
result:
ok "7"
Test #2:
score: 0
Accepted
time: 6ms
memory: 14024kb
input:
123 456 789 123456789
output:
567982455
result:
ok "567982455"
Test #3:
score: 0
Accepted
time: 6ms
memory: 12148kb
input:
0 0 0 1000000000000000000
output:
0
result:
ok "0"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3868kb
input:
628 314 157 1
output:
628
result:
ok "628"
Test #5:
score: 0
Accepted
time: 1ms
memory: 3884kb
input:
167 924 167 2
output:
924
result:
ok "924"
Test #6:
score: 0
Accepted
time: 3ms
memory: 12136kb
input:
1048575 1048575 1048575 1000000000000000000
output:
1048575
result:
ok "1048575"
Test #7:
score: -100
Wrong Answer
time: 825ms
memory: 39536kb
input:
287144 758614 992207 1000000000000000000
output:
256541677
result:
wrong answer 1st words differ - expected: '638555367', found: '256541677'