Do Use FFT

题意

给定序列\(\{A\},\{B\},\{C\}\),求序列\(\{ans_i\}\),其中
\(ans_k\sum_{1 \leq i \leq N} \left( C_i \times \prod_{1 \leq j \leq k} (A_i+B_j) \right)\)

做法

\(T(x)=\sum\limits_{i=1}^N\frac{C_i}{1-A_ix}\)
\(P_{[L,R]}=\prod\limits_{i=L}^R (x+B_i)\)

\(ans_k=[x^0]T(x)P_{[1,k]}(1/x)\)

考虑求\(T(x)=\frac{\sum\limits_{i=1}^N C_i\prod\limits_{j\neq i}(1-A_jx)}{\prod\limits_{i=1}^n(1-A_ix)}\),求\(G(x)\sum\limits_{i=1}^N C_i\prod\limits_{j\neq i}(1-A_jx)\)

分治fft,令\(G_{[L,R]}(x)=\sum\limits_{i=L}^R C_i\prod\limits_{j\neq i,j\in[L,R]}(1-A_jx)\),令\(H_{[L,R]}(x)=\prod\limits_{i=L}^R (1-A_ix)\)
\(G_{[L,R]}(x)=G_{[L,mid]}(x)H_{(mid,R]}(x)+H_{[l,mid]}(x)G_{(mid,R]}(x)\)

考虑求\([x^0]T(x)P_{[1,k]}(1/x)\)
\(Solve(1,n)\)传入\(T(x)\)
考虑得到\(Solve(l,r)\),向\(Solve(l,mid)\)传入\(Solve(l,r)\);向\(Solve(mid+1,r)\)传入\(Solve(l,r)\cdot P_{[l,mid]}(1/x)\)
由于最后我们仅需得到\([x^0]\)的系数,那么\(Solve(l,r)\)保留\([x^0],[x^1],\cdots,[x^{r-l+1}]\)项系数即可。

总复杂度为\(O(nlog^2n)\)

posted @ 2021-03-08 12:40  Grice  阅读(187)  评论(0编辑  收藏  举报