【题解】P10588 「ALFR Round 2」D 超立方体
Starrykiller
·
·
题解
答案显然为
\left[\prod_{1\le i\le n} x_i^{[i\le l]}\right]\left(\sum_{1\le i\le n} x_i\right)^m \bmod (x_1^2-1)\bmod \cdots \bmod (x_ n^2-1)
考虑手动做 FWT:
初始时,序列 f_i=[i=2^k]。然后做长度为 2^n 的 FWT 之后得到
\begin{aligned}
\hat f_i&=\sum_{0\le j\lt 2^n} (-1)^{\operatorname{popcount}(i\operatorname{and}j)} f_j \\
&=\sum_{0\le j\lt n} (-1)^{[j\in i]} \\
&=n-2\operatorname{popcount}(i)
\end{aligned}
然后令 \hat f_i\gets {\hat f_i}^m,再 IFWT 回去:
\begin{aligned}
f'_i&=\frac{1}{2^n}\sum_{0\le j\lt 2^n} (-1)^{\operatorname{popcount}(i\operatorname{and}j)} \hat f_j \\
\end{aligned}
我们关心的实际上是 f_{2^l-1},也就是,低 l 位是 1。注意到只和 \operatorname{popcount} 有关系,不妨枚举低 l 位的 \operatorname{popcount} 和后 (n-l) 位的 \operatorname{popcount}:
\begin{aligned}
\mathrm{answer}&=\frac{1}{2^n}\sum_{0\le p\le l}(-1)^p{l\choose p}\sum_{0\le q\le n-l}{n-l\choose q} (n-2(p+q))^m
\end{aligned}
枚举 p+q 的值,得到
\begin{aligned}
\mathrm{answer}&=\frac{1}{2^n}\sum_{0\le i\le n}(n-2i)^m\sum_{p+q=i}(-1)^p{l\choose p}{n-l\choose q}
\end{aligned}
使用 DFT,时间复杂度 \Theta(n\log n)。