版本比较
数学:FWT
正文
增加 9 行删除 9 行
1234556789241 行未改动全部展开25125225325425525525625725825926026026126226226326426526626726726826926927027127227327427427527627627727827928028128128228328428538 行未改动数学:FWT 与集合幂级数
# FWT
快速沃尔什变换 Fast Walsh-Hadamard transform. 快速沃尔什变换 Fast Walsh-Hadamard transform.
用于计算位运算卷积。
## 异或卷积241 行未改动全部展开ll tmpa[N], tmpb[N];int main() { ios::sync_with_stdio(0); cin.tie(0);
cin >> n; n = 1 << n; for (int i = 0; i < n; ++i) cin >> a[i]; for (int i = 0; i < n; ++i) cin >> b[i];
memcpy(tmpa, a, sizeof a); memcpy(tmpb, b, sizeof b);
orfwt(a, n, 1); orfwt(b, n, 1); for (int i = 0; i < n; ++i) c[i] = a[i] * b[i] % mod; orfwt(c, n, -1); for (int i = 0; i < n; ++i) cout << (c[i] + mod) % mod << " \n"[i == n - 1];
memcpy(a, tmpa, sizeof a); memcpy(b, tmpb, sizeof b);
andfwt(a, n, 1); andfwt(b, n, 1); for (int i = 0; i < n; ++i) c[i] = a[i] * b[i] % mod; andfwt(c, n, -1); for (int i = 0; i < n; ++i) cout << (c[i] + mod) % mod << " \n"[i == n - 1];
memcpy(a, tmpa, sizeof a); memcpy(b, tmpb, sizeof b);
xorfwt(a, n, 1); xorfwt(b, n, 1); for (int i = 0; i < n; ++i) c[i] = a[i] * b[i] % mod; xorfwt(c, n, qpow(2, mod - 2)); for (int i = 0; i < n; ++i) cout << c[i] << " ";
return 0;}```
38 行未改动