P6800 【模板】Chirp Z-Transform
2022/7/14 23:21:52
本文主要是介绍P6800 【模板】Chirp Z-Transform,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
\(\text{Solution}\)
考虑把\(c^i\)带入多项式得
\[ans_i = \sum_{j = 0}^{n - 1}a_jc^{ij} \]利用组合数把\(c^{ij}\)拆开,\(ij = \binom{i + j}{2} - \binom{i}{2} - \binom{j}{2}\),证明把组合数拆开即可。
\[ans_i = \sum_{j = 0}^{n - 1}a_jc^{\binom{i + j}{2} - \binom{i}{2} - \binom{j}{2}} \]\[ans_i = c^{-\binom{i}{2}}\sum_{j = 0}^{n - 1}a_jc^{-\binom{j}{2}}c^{\binom{i + j}{2}} \]这时是一个卷积,只是有点不同,考虑设\(A_i = c^{\binom{i}{2}}\),\(B_{n - 1 - i} = a_ic^{-\binom{i}{2}}\)。枚举一个\(i+j\)加\(n - j\)即可。
\[ans_i = c^{-\binom{i}{2}}\sum_{(i + j) + (n - 1 - j) = i + n - 1}A_{i + j}B_{n - 1 - j} \]\(\text{Code}\)
#include<cstdio> #include<algorithm> #define LL long long using namespace std; const int P = 998244353; const int N = 1e6 + 5; int n,m,rev[N * 5]; LL c,a[N],b[N],f[N * 5],g[N * 5]; LL fpow(LL x,LL y) { LL res = 1; for (; x; x >>= 1,y = y * y % P) if (x & 1) res = res * y % P; return res; } void NTT(LL *f,int len,int fl) { if (len == 1) return; for (int i = 0; i < len; i++) if (i < rev[i]) swap(f[i],f[rev[i]]); for (int l = 1; l < len; l <<= 1) { LL I = fpow((P - 1) / (l << 1),3); if (fl == -1) I = fpow(P - 2,I); for (int i = 0; i < len; i += (l << 1)) { LL W = 1; for (int j = 0; j < l; j++,W = W * I % P) { LL x = f[i + j],y = W * f[i + j + l] % P; f[i + j] = (x + y) % P,f[i + j + l] = (x - y + P) % P; } } } } int main() { scanf("%d%lld%d",&n,&c,&m); for (int i = 0; i < n; i++) scanf("%lld",&a[i]); LL ic = fpow(P - 2,c),mc; mc = ic,b[0] = b[1] = 1LL; for (int i = 2; i < (n > m ? n : m); i++) b[i] = b[i - 1] * mc % P,mc = mc * ic % P; mc = c,f[0] = f[1] = 1LL; for (int i = 2; i < n + m - 1; i++) f[i] = f[i - 1] * mc % P,mc = mc * c % P; for (int i = 0; i < n; i++) g[n - 1 - i] = a[i] * b[i] % P; int len = 1,bit = 0; while (len <= 2 * n + m - 3) len <<= 1,bit++; for (int i = 1; i < len; i++) rev[i] = (rev[i >> 1] >> 1) | ((i & 1) << bit - 1); NTT(f,len,1),NTT(g,len,1); for (int i = 0; i < len; i++) f[i] = f[i] * g[i] % P; NTT(f,len,-1); LL inv = fpow(P - 2,len); for (int i = 0; i < m; i++) printf("%lld ",b[i] * f[n + i - 1] % P * inv % P); }
这篇关于P6800 【模板】Chirp Z-Transform的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-12-26怎么使用nsenter命令进入容器?-icode9专业技术文章分享
- 2024-12-26导入文件提示存在乱码,请确定使用的是UTF-8编码怎么解决?-icode9专业技术文章分享
- 2024-12-26csv文件怎么设置编码?-icode9专业技术文章分享
- 2024-12-25TypeScript基础知识详解
- 2024-12-25安卓NDK 是什么?-icode9专业技术文章分享
- 2024-12-25caddy 可以定义日志到 文件吗?-icode9专业技术文章分享
- 2024-12-25wordfence如何设置密码规则?-icode9专业技术文章分享
- 2024-12-25有哪些方法可以实现 DLL 文件路径的管理?-icode9专业技术文章分享
- 2024-12-25错误信息 "At least one element in the source array could not be cast down to the destination array-icode9专业技术文章分享
- 2024-12-25'flutter' 不是内部或外部命令,也不是可运行的程序 或批处理文件。错误信息提示什么意思?-icode9专业技术文章分享