# BZOJ 3625 [Codeforces Round #250]小朋友和二叉树 多项式开根

## 代码:

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <algorithm>
#define N 262144
#define mod 998244353
using namespace std;
typedef int ll;
int n,m;
ll c[N],Inv2,root_c[N],inv_root_c[N];
int rev[N];
long long Quick_Power(long long x,ll y,ll MOD)
{
long long ret=1;
while(y)
{
if(y&1)ret=(ret*x)%MOD;
x=(x*x)%MOD;
y>>=1;
}
return ret;
}
void NTT(ll *a,int n,int f)
{
for(int i=0;i<n;i++)if(i<rev[i])swap(a[i],a[rev[i]]);
for(int h=2;h<=n;h<<=1)
{
ll wn=Quick_Power(3,(mod-1)/h,mod);
for(int i=0;i<n;i+=h)
{
ll w=1;
for(int j=0;j<(h>>1);j++,w=(long long)w*wn%mod)
{
ll t=(long long)a[i+j+(h>>1)]*w%mod;
a[i+j+(h>>1)]=((a[i+j]-t)%mod+mod)%mod;
a[i+j]=(a[i+j]+t)%mod;
}
}
}
if(f==-1)
{
for(int i=1;i<(n>>1);i++)swap(a[i],a[n-i]);
ll inv=Quick_Power(n,mod-2,mod);
for(int i=0;i<n;i++)a[i]=(long long)a[i]*inv%mod;
}
}
void Get_Inv(ll *a,ll *b,int n)
{
static ll temp[N];
if(n==1)
{
b[0]=Quick_Power(a[0],mod-2,mod);
return;
}
Get_Inv(a,b,n>>1);
memcpy(temp,a,sizeof(a[0])*n);
memset(temp+n,0,sizeof(a[0])*n);
int m=n,L=0,nn=n;
for(n=1;n<=m;n<<=1)L++;
for(int i=0;i<n;i++)rev[i]=(rev[i>>1]>>1)|((i&1)<<(L-1));
NTT(temp,n,1),NTT(b,n,1);
for(int i=0;i<n;i++)
temp[i]=(long long)b[i]*(((2ll-(long long)temp[i]*b[i]%mod)%mod+mod)%mod)%mod;
NTT(temp,n,-1);
for(int i=0;i<(n>>1);i++)b[i]=temp[i];
memset(b+nn,0,sizeof(b[0])*nn);
n=nn;
}
void Get_Root(ll *a,ll *b,int n)
{
static ll temp[N],inv_b[N];
if(n==1)
{
b[0]=1;
return;
}
Get_Root(a,b,n>>1);
memset(inv_b,0,sizeof(a[0])*n);
Get_Inv(b,inv_b,n);
memcpy(temp,a,sizeof(a[0])*n);
memset(temp+n,0,sizeof(a[0])*n);
int m=n,L=0,nn=n;
for(n=1;n<=m;n<<=1)L++;
for(int i=0;i<n;i++)rev[i]=(rev[i>>1]>>1)|((i&1)<<(L-1));
NTT(temp,n,1),NTT(b,n,1),NTT(inv_b,n,1);
for(int i=0;i<n;i++)
temp[i]=(long long)Inv2*((b[i]+(long long)inv_b[i]*temp[i]%mod)%mod)%mod;
NTT(temp,n,-1);
for(int i=0;i<(n>>1);i++)b[i]=temp[i];
memset(b+nn,0,sizeof(b[0])*nn);
n=nn;
}
int main()
{
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)
{
ll x;
scanf("%d",&x);
c[x]++;
}
Inv2=Quick_Power(2,mod-2,mod);
c[0]=((1-c[0])%mod+mod)%mod;
for(int i=1;i<=100000;i++)
c[i]=((-4*c[i])%mod+mod)%mod;
int l;
for(l=1;l<=m;l<<=1);
Get_Root(c,root_c,l);
root_c[0]=(1+root_c[0])%mod;
Get_Inv(root_c,inv_root_c,l);
for(int i=0;i<=100000;i++)
inv_root_c[i]=((long long)2*inv_root_c[i])%mod;
for(int i=1;i<=m;i++)
printf("%d\n",inv_root_c[i]);
} 

05-18 147

01-21 523

12-22 506

09-11 2671

06-05 23

03-25 221

05-08 74

07-27 159

03-04 294

06-12 192

#### Codeforces Round #566 (Div. 2)-E. Product Oriented Recurrence

©️2020 CSDN 皮肤主题: 编程工作室 设计师: CSDN官方博客

1.余额是钱包充值的虚拟货币，按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载，可以购买VIP、C币套餐、付费专栏及课程。