快速沃尔什变换模板
Posted hs-black
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了快速沃尔什变换模板相关的知识,希望对你有一定的参考价值。
inline void FWT_or(ll *f, ll x = 1) {
for (int p = 2, k = 1;p <= n; p <<= 1, k <<= 1)
for (int i = 0;i < n; i += p)
for (int j = 0;j < k; j++)
if (~x) f[i+j+k] = (f[i+j+k] + f[i+j]) % P;
else f[i+j+k] = (f[i+j+k] - f[i+j] + P) % P;
}
inline void FWT_and(ll *f, ll x = 1) {
for (int p = 2, k = 1;p <= n; p <<= 1, k <<= 1)
for (int i = 0;i < n; i += p)
for (int j = 0;j < k; j++)
if (~x) f[i+j] = (f[i+j+k] + f[i+j]) % P;
else f[i+j] = (f[i+j] - f[i+j+k] + P) % P;
}
inline void FWT_xor(ll *f, ll opt = 1) {
for (int p = 2, k = 1;p <= n; p <<= 1, k <<= 1)
for (int i = 0;i < n; i += p)
for (int j = 0;j < k; j++) {
ll x = f[i+j], y = f[i+j+k];
f[i+j] = (x + y) % P;
f[i+j+k] = (x + P - y) % P;
if (opt==-1) f[i+j] = f[i+j] * inv2 % P, f[i+j+k] = f[i+j+k] * inv2 % P;
}
}
以上是关于快速沃尔什变换模板的主要内容,如果未能解决你的问题,请参考以下文章