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的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程