QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#479793 | #56. Nim Product | NOI_AK_ME# | 100 ✓ | 329ms | 5712kb | C++23 | 2.1kb | 2024-07-15 20:54:57 | 2024-07-15 20:54:59 |
Judging History
answer
#include <bits/stdc++.h>
#define ctz __builtin_ctz
using std::cin;
using std::cout;
typedef unsigned short u16;
typedef unsigned int u32;
namespace nimbers {
constexpr u32 n2f[16] = { 0x0001u, 0x8ff5u, 0x6cbfu, 0xa5beu, 0x761au, 0x8238u, 0x4f08u, 0x95acu,
0xf340u, 0x1336u, 0x7d5eu, 0x86e7u, 0x3a47u, 0xe796u, 0xb7c3u, 0x0008u },
f2n[16] = { 0x0001u, 0x2827u, 0x392bu, 0x8000u, 0x20fdu, 0x4d1du, 0xde4au, 0x0a17u,
0x3464u, 0xe3a9u, 0x6d8du, 0x34bcu, 0xa921u, 0xa173u, 0x0ebcu, 0x0e69u };
inline u32 nimber2field(u32 x) {
u32 y = 0;
for (; x; x &= x - 1) y ^= n2f[ctz(x)];
return y;
}
inline u32 field2nimber(u32 x) {
u32 y = 0;
for (; x; x &= x - 1) y ^= f2n[ctz(x)];
return y;
}
inline u32 __builtin_double(u32 x) { return x << 1 ^ (x < 0x8000u ? 0 : 0x1681fu); }
u16 ln[65536], exp[131075], *Hexp = exp + 3, *H2exp = exp + 6;
inline void init() {
int i;
for (*exp = i = 1; i < 65535; ++i) exp[i] = __builtin_double(exp[i - 1]);
for (i = 1; i < 65535; ++i) exp[i] = field2nimber(exp[i]), ln[exp[i]] = i;
memcpy(exp + 65535, exp, 131070);
memcpy(exp + 131070, exp, 10);
}
inline u16 product(u16 A, u16 B) { return A && B ? exp[ln[A] + ln[B]] : 0; }
inline u16 H(u16 A) { return A ? Hexp[ln[A]] : 0; }
inline u16 H2(u16 A) { return A ? H2exp[ln[A]] : 0; }
inline u16 Hproduct(u16 A, u16 B) { return A && B ? Hexp[ln[A] + ln[B]] : 0; }
inline u32 product(u32 A, u32 B) {
u16 a = A & 65535, b = B & 65535, c = A >> 16, d = B >> 16, e = product(a, b);
return u32(product(u16(a ^ c), u16(b ^ d)) ^ e) << 16 | (Hproduct(c, d) ^ e);
}
inline u32 H(u32 A) {
u16 a = A & 65535, b = A >> 16;
return H(u16(a ^ b)) << 16 | H2(b);
}
}
u32 SA, SB, SC;
u32 ans[1000001];
u32 next() {
SA ^= SA << 16, SA ^= SA >> 5, SA ^= SA << 1;
u32 t = SA;
return SA = SB, SB = SC, SC ^= t ^ SA;
}
int main() {
int T;
u32 a, b, c = 0;
nimbers::init();
for (cin >> T >> SA >> SB >> SC; T; --T) a = next() + c, b = next(), c = nimbers::product(a, b);
cout << c << '\n';
return 0;
}
详细
Test #1:
score: 25
Accepted
time: 0ms
memory: 3924kb
input:
10 274134852 279286565 744539633
output:
2002382043
result:
ok single line: '2002382043'
Test #2:
score: 25
Accepted
time: 1ms
memory: 3928kb
input:
1000 734766235 309378503 610268282
output:
2106551671
result:
ok single line: '2106551671'
Test #3:
score: 25
Accepted
time: 2ms
memory: 4000kb
input:
30000 784936363 827067061 800454511
output:
554318281
result:
ok single line: '554318281'
Test #4:
score: 25
Accepted
time: 329ms
memory: 5712kb
input:
30000000 72129929 485897764 129463885
output:
92762235
result:
ok single line: '92762235'