QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#536970 | #56. Nim Product | ckiseki | 100 ✓ | 702ms | 12904kb | C++20 | 2.4kb | 2024-08-29 18:22:29 | 2024-08-29 18:22:30 |
Judging History
answer
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#ifdef CKISEKI
#define safe cerr<<__PRETTY_FUNCTION__<<" line "<<__LINE__<<" safe\n"
#define debug(a...) debug_(#a, a)
#define orange(a...) orange_(#a, a)
template <typename ...T>
void debug_(const char *s, T ...a) {
cerr << "\e[1;32m(" << s << ") = (";
int cnt = sizeof...(T);
(..., (cerr << a << (--cnt ? ", " : ")\e[0m\n")));
}
template <typename I>
void orange_(const char *s, I L, I R) {
cerr << "\e[1;32m[ " << s << " ] = [ ";
for (int f = 0; L != R; ++L)
cerr << (f++ ? ", " : "") << *L;
cerr << " ]\e[0m\n";
}
#else
#define safe ((void)0)
#define debug(...) safe
#define orange(...) safe
#endif
namespace {
using lld = int64_t;
using llf = long double;
using llu = uint64_t;
int lowbit(int x) {
return x & -x;
}
#define rep(i, r) for (int i = 0; i < r; i++)
struct NimProd {
llu bit_prod[16][16]{}, prod[16][65536]{};
llu lg[65536], pw[65536];
NimProd() {
rep(i, 16) rep(j, 16) if (i & j) {
int a = lowbit(i & j);
bit_prod[i][j] = bit_prod[i ^ a][j] ^
bit_prod[(i ^ a) | (a-1)][(j ^ a) | (i & (a-1))];
} else bit_prod[i][j] = 1ULL << (i | j);
rep(c, 16) rep(x, 65536) if (x)
prod[c][x] = bit_prod[c][__lg(x & -x)] ^ prod[c][x & (x - 1)];
llu x = 1;
rep(i, 65535) {
llu r = 0;
rep(c, 16) r ^= prod[c][x]; // G = 65535
lg[x] = i, pw[i] = x, x = r;
}
}
template <int K>
llu mul(llu a, llu b) const {
if (!a || !b) return 0;
if constexpr (K <= 16)
return pw[(lg[a] + lg[b]) % 65535];
constexpr llu H = K / 2, mask = (1ULL << H) - 1;
llu au = a >> H, al = a & mask;
llu bu = b >> H, bl = b & mask;
llu L = mul<H>(al, bl);
llu U = mul<H>(mul<H>(au, bu), 1ULL << (H - 1));
llu M = mul<H>(au ^ al, bu ^ bl) ^ L;
return L ^ U ^ (M << H);
}
llu operator()(llu a, llu b) const {
return mul<32>(a, b); }
};
NimProd nim_prod;
unsigned int SA, SB, SC;
unsigned int rng() {
SA ^= SA << 16;
SA ^= SA >> 5;
SA ^= SA << 1;
unsigned int t = SA;
SA = SB;
SB = SC;
SC ^= t ^ SA;
return SC;
}
}
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int T;
uint32_t lastans = 0;
cin >> T >> SA >> SB >> SC;
while (T--) {
uint32_t x = rng() + lastans;
uint32_t y = rng();
lastans = nim_prod(x, y);
}
cout << lastans << '\n';
}
// tioj-proxy nonce=0491f31c596d65a2f0b2c4a41b2fd2d4c05da2b0127294834fb941784285e038
Details
Tip: Click on the bar to expand more detailed information
Pretests
Final Tests
Test #1:
score: 25
Accepted
time: 9ms
memory: 12840kb
input:
10 274134852 279286565 744539633
output:
2002382043
result:
ok single line: '2002382043'
Test #2:
score: 25
Accepted
time: 8ms
memory: 12852kb
input:
1000 734766235 309378503 610268282
output:
2106551671
result:
ok single line: '2106551671'
Test #3:
score: 25
Accepted
time: 10ms
memory: 12796kb
input:
30000 784936363 827067061 800454511
output:
554318281
result:
ok single line: '554318281'
Test #4:
score: 25
Accepted
time: 702ms
memory: 12904kb
input:
30000000 72129929 485897764 129463885
output:
92762235
result:
ok single line: '92762235'