跳到正文

题解

【题解】P10588 「ALFR Round 2」D 超立方体

Starrykiller约 2 分钟
原文
文章信息与版本

文章信息

发布
2024年12月18日
收录
2026年8月12日
更新
2026年11月15日
篇幅
约 2 分钟
获赞
7
题目
P10588

版本

  1. v2当前
  2. v1

答案显然为

[∏1≤i≤nxi[i≤l]](∑1≤i≤nxi)m mod (x12−1) mod ⋯ mod (xn2−1)\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:

初始时,序列 fi=[i=2k]f_i=[i=2^k]。然后做长度为 2n2^n 的 FWT 之后得到

f^i=∑0≤j<2n(−1)popcount⁡(iand⁡j)fj=∑0≤j<n(−1)[j∈i]=n−2popcount⁡(i)\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}

然后令 f^i←f^im\hat f_i\gets {\hat f_i}^m,再 IFWT 回去:

fi′=12n∑0≤j<2n(−1)popcount⁡(iand⁡j)f^j\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}

我们关心的实际上是 f2l−1f_{2^l-1},也就是,低 ll 位是 11。注意到只和 popcount⁡\operatorname{popcount} 有关系,不妨枚举低 ll 位的 popcount⁡\operatorname{popcount} 和后 (n−l)(n-l) 位的 popcount⁡\operatorname{popcount}:

answer=12n∑0≤p≤l(−1)p(lp)∑0≤q≤n−l(n−lq)(n−2(p+q))m\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+qp+q 的值,得到

answer=12n∑0≤i≤n(n−2i)m∑p+q=i(−1)p(lp)(n−lq)\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,时间复杂度 Θ(nlog⁡n)\Theta(n\log n)。

原文
存档评论2 条抓取于