目前我了解的FWT的功能就是在 $O(nlog n) 时间复杂度内求:$
$C_k = sum_{i|j=k}a_ib_j$
$C_k = sum_{i&j=k}a_ib_j$
$C_k = sum_{ioplus j=k}a_ib_j$
其思想和 $FFT$ 很类似。把原多项式 $A$ 转化成另一个多项式 $FWT(A)$。
然后 $A oplus B = IFWT(FWT(A) times FWT(B))$
其中 $oplus$ 表示一些位运算。
然后接下来的问题是针对不同的位运算,去找出如何求 $FWT$ 和 $IFWT$。
一些定义
$A = [a_0, a_1, a_2, …, a_{n-1}]$
设 $A$ 的长度为 $2$ 的幂次,将 $A = [A_0, A_1]$ 分成长度相同的两部分。
OR
$C = A|B = [sum_{i|j=0}a_ib_j, sum_{i|j=1}a_ib_j, sum_{i|j=2}a_ib_j, …, sum_{i|j=k}a_ib_j]$
$C_k = sum_{i|j=k}a_ib_j$
$FWT(A) = [sum_{i | 0 = 0}a_i, sum_{i | 1 = 1}a_i, sum_{i | 2 = 2}a_i, …, sum_{i | (n-1) = (n-1)}a_{n-1}]$
FWT 变换所满足的规律
$$FWT(A) = [FWT(A_0), FWT(A_0 + A_1)]$$
FWT 变换所满足的性质
$FWT(A+B) = FWT(A) + FWT(B)$
$FWT(A|B) = FWT(A) times FWT(B)$
$FWT(A|B) = FWT([(A|B)_0, (A|B)_1])$
$ = [FWT((A|B)_0), FWT((A|B)_0 + (A|B)_1)]$
$ = [FWT(A_0 | B_0), FWT(A_0 | B_0 + A_0 | B_1 + A_1 | B_0 + A_1 | B_1)]$
$ = [FWT(A_0) times FWT(B_0), FWT(A_0) times FWT(B_0) + FWT(A_0) times FWT(B_1) + FWT(A_1) times FWT(B_0) + FWT(A_1) times FWT(B_1))]$
$ = [FWT(A_0) times FWT(B_0), (FWT(A_0) + FWT(A_1)) times (FWT(B_0) + FWT(B_1))]$
$ = [FWT(A_0), FWT(A_0 + A_1)] times [FWT(B_0), FWT(B_0 + B_1)]$
$ = FWT(A) times FWT(B)$
IFWT 变换所满足的规律
$$IFWT(A) = [IFWT(A_0), IFWT(A_1) - IFWT(A_0)]$$
AND
$C = A&B = [sum_{i&j=0}a_ib_j, sum_{i&j=1}a_ib_j, sum_{i&j=2}a_ib_j, …, sum_{i&j=k}a_ib_j]$
$C_k = sum_{i&j=k}a_ib_j$
FWT 变换所满足的规律
$$FWT(A) = [FWT(A_0 + A_1), FWT(A_1)]$$
FWT 变换所满足的性质
$FWT(A+B) = FWT(A) + FWT(B)$
$FWT(A&B) = FWT(A) times FWT(B)$
IFWT 变换所满足的规律
$$IFWT(A) = [IFWT(A_0) - IFWT(A_1), IFWT(A_1)]$$
XOR
$C = Aoplus B = [sum_{ioplus j=0}a_ib_j, sum_{ioplus j=1}a_ib_j, sum_{ioplus j=2}a_ib_j, …, sum_{ioplus j=k}a_ib_j]$
$C_k = sum_{ioplus j=k}a_ib_j$
FWT 变换所满足的规律
$$FWT(A) = [FWT(A_0) + FWT(A_1), FWT(A_0) - FWT(A_1)]$$
FWT 变换所满足的性质
$FWT(A+B) = FWT(A) + FWT(B)$
$FWT(Aoplus B) = FWT(A) times FWT(B)$
IFWT 变换所满足的规律
$$IFWT(A) = [frac{IFWT(A_0) + IFWT(A_1)}{2}, frac{IFWT(A_0) - IFWT(A_1)}{2}$$
代码
1 |
|