BZOJ3625 [Codeforces Round #250]小朋友和二叉树

BZOJ3625

http://www.lydsy.com/JudgeOnline/problem.php?id=3625

 

 

 

#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#define gc getchar()
#define rep(i,l,r) for(register int i=l;i<=r;++i)
#define Rep(i,l,r) for(register int i=l;i<r;++i)
using namespace std;
const int N=(1<<18)+100,mod=998244353,g=3,inv2=(mod+1)>>1;
int n,x,m,c[N],a[N],f[N],t[N],ib[N],p[N],gn[233];
inline int fp(int a,int b){
	int res=1;
	while(b){
		if(b&1)res=1ll*res*a%mod;
		a=1ll*a*a%mod;b>>=1;
	}
	return res;
}
inline void init(){
	Rep(t,0,30)gn[t]=fp(3,(mod-1)/(1<<(t+1)));
}
inline void dft(int *a,int d,int f){
	Rep(i,0,d)if(i<p[i])swap(a[i],a[p[i]]);
	for(register int i=1,t=0,v;i<d;i<<=1,++t)
		for(register int j=0,w=1;j<d;w=1,j+=(i<<1))
			for(register int k=j;k<i+j;++k,w=1ll*w*gn[t]%mod)
				v=1ll*w*a[i+k]%mod,a[i+k]=(a[k]-v+mod)%mod,a[k]=(a[k]+v)%mod;
	if(f==1)return;reverse(a+1,a+d);register int ny=fp(d,mod-2);
	for(register int i=0;i<d;++i)a[i]=1ll*a[i]*ny%mod;
}
inline void inverse(int *a,int *b,int l){
   if(l==1){b[0]=fp(a[0],mod-2);return;}
   inverse(a,b,l>>1);
   int d=1,lg2=-1;while(d<(l<<1))d<<=1,++lg2;
   Rep(i,0,d)p[i]=(p[i>>1]>>1)^((i&1)<<lg2);
   Rep(i,0,l)t[i]=a[i];
   Rep(i,l,d)t[i]=0;
   dft(t,d,1);dft(b,d,1);
   Rep(i,0,d)b[i]=1ll*b[i]*(2-1ll*t[i]*b[i]%mod+mod)%mod;
   dft(b,d,-1);
   Rep(i,l,d)b[i]=0;
}
inline void Sqrt(int *a,int *b,int l){
   if(l==1){b[0]=1;return;}
   Sqrt(a,b,l>>1);
   int d=1,lg2=-1;while(d<(l<<1))d<<=1,++lg2;
   Rep(i,0,d)ib[i]=0;
   inverse(b,ib,l);
   Rep(i,0,d)p[i]=(p[i>>1]>>1)^((i&1)<<lg2);
   Rep(i,0,l)t[i]=a[i];
   Rep(i,l,d)t[i]=0;
   dft(t,d,1);dft(b,d,1);dft(ib,d,1);
   Rep(i,0,d)b[i]=1ll*inv2*(b[i]+1ll*t[i]*ib[i]%mod)%mod;
   dft(b,d,-1);
   Rep(i,l,d)b[i]=0;
}
inline int read(){
	char c;while(c=gc,c==' '||c=='\n');int data=c-48;
	while(c=gc,c>='0'&&c<='9')data=(data<<1)+(data<<3)+c-48;return data;
}
int main(){
	init();n=read();m=read();c[0]=1;
	rep(i,1,n)c[read()]-=4;
	rep(i,0,m)if(c[i]<0)c[i]+=mod;
	int len=1;while(len<=m)len<<=1;Sqrt(c,a,len);
	++a[0];if(a[0]>=mod)a[0]-=mod;inverse(a,f,len);
	rep(i,1,m)printf("%d\n",(f[i]<<1)%mod);
	return 0;
}

  

posted @ 2018-02-20 18:24  Stump  阅读(...)  评论(...编辑  收藏

Respond.js | Bootstrap中文网