题意:有一个集合,求有多少形态不同的二叉树满足每个点的权值都属于这个集合并且总点权等于i

题解:先用生成函数搞出来\(f(x)=f(x)^2*c(x)+1\)

然后转化一下变成\(f(x)=\frac{2}{1+\sqrt{1-4*c(x)}}\)

然后多项式开根和多项式求逆即可(先对下面的项开根,然后再求逆)

多项式开根:

\(B(x)^2=A(x) \bmod x^{ \lfloor \frac{n}{2} \rfloor}\)

\(B'(x)^2=A(x) \bmod x^{ \lfloor \frac{n}{2} \rfloor}\)

\(B(x)^2-B'(x)^2\equiv 0\),\((B(x)+B'(x))*(B(x)-B'(x))\equiv 0\),取\(B(x)=B'(x)\)

\(B(x)^2-2*B(x)*B'(x)+B'(x)^2\equiv0\),

\(B(x)\equiv \frac{A(x)+B'(x)^2}{2*B'(x)}\)

//#pragma GCC optimize(2)
//#pragma GCC optimize(3)
//#pragma GCC optimize(4)
//#pragma GCC optimize("unroll-loops")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#define fi first
#define se second
#define db double
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define ll long long
#define vi vector<int>
#define mod 998244353
#define ld long double
#define C 0.5772156649
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#define pll pair<ll,ll>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define pii pair<int,int>
//#define cd complex<double>
#define ull unsigned long long
#define base 1000000000000000000
#define Max(a,b) ((a)>(b)?(a):(b))
#define Min(a,b) ((a)<(b)?(a):(b))
#define fin freopen("a.txt","r",stdin)
#define fout freopen("a.txt","w",stdout)
#define fio ios::sync_with_stdio(false);cin.tie(0)
template<typename T>
inline T const& MAX(T const &a,T const &b){return a>b?a:b;}
template<typename T>
inline T const& MIN(T const &a,T const &b){return a<b?a:b;}
inline void add(ll &a,ll b){a+=b;if(a>=mod)a-=mod;}
inline void sub(ll &a,ll b){a-=b;if(a<0)a+=mod;}
inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
inline ll qp(ll a,ll b){ll ans=1;while(b){if(b&1)ans=ans*a%mod;a=a*a%mod,b>>=1;}return ans;}
inline ll qp(ll a,ll b,ll c){ll ans=1;while(b){if(b&1)ans=ans*a%c;a=a*a%c,b>>=1;}return ans;} using namespace std; const double eps=1e-8;
const ll INF=0x3f3f3f3f3f3f3f3f;
const int N=100000+10,maxn=400000+10,inf=0x3f3f3f3f; ll a[N<<3],b[N<<3],c[N<<3],d[N<<3],tmp[N<<3],inv2=qp(2,mod-2);
int rev[N<<3];
void getrev(int bit)
{
for(int i=0;i<(1<<bit);i++)
rev[i]=(rev[i>>1]>>1) | ((i&1)<<(bit-1));
}
void ntt(ll *a,int n,int dft)
{
for(int i=0;i<n;i++)
if(i<rev[i])
swap(a[i],a[rev[i]]);
for(int step=1;step<n;step<<=1)
{
ll wn=qp(3,(mod-1)/(step*2));
if(dft==-1)wn=qp(wn,mod-2);
for(int j=0;j<n;j+=step<<1)
{
ll wnk=1;
for(int k=j;k<j+step;k++)
{
ll x=a[k];
ll y=wnk*a[k+step]%mod;
a[k]=(x+y)%mod;a[k+step]=(x-y+mod)%mod;
wnk=wnk*wn%mod;
}
}
}
if(dft==-1)
{
ll inv=qp(n,mod-2);
for(int i=0;i<n;i++)a[i]=a[i]*inv%mod;
}
}
void pol_inv(int deg,ll *a,ll *b)
{
if(deg==1){b[0]=qp(a[0],mod-2);return ;}
pol_inv((deg+1)>>1,a,b);
int sz=0;while((1<<sz)<=deg)sz++;
getrev(sz);int len=1<<sz;
for(int i=0;i<deg;i++)tmp[i]=a[i];
for(int i=deg;i<len;i++)tmp[i]=0;
ntt(tmp,len,1),ntt(b,len,1);
for(int i=0;i<len;i++)
b[i]=(2ll-tmp[i]*b[i]%mod+mod)%mod*b[i]%mod;
ntt(b,len,-1);
for(int i=deg;i<len;i++)b[i]=0;
}
void pol_sqrt(int deg,ll *a,ll *b)
{
if(deg==1){b[0]=1;return ;}
pol_sqrt((deg+1)>>1,a,b);
int sz=0;while((1<<sz)<=deg)sz++;
getrev(sz);int len=1<<sz;
for(int i=0;i<len;i++)d[i]=0;
pol_inv(deg,b,d);
for(int i=0;i<deg;i++)tmp[i]=a[i];
for(int i=deg;i<len;i++)tmp[i]=0;
ntt(tmp,len,1),ntt(b,len,1),ntt(d,len,1);
for(int i=0;i<len;i++)
b[i]=(tmp[i]*d[i]%mod+b[i])%mod*inv2%mod;
ntt(b,len,-1);
for(int i=deg;i<len;i++)b[i]=0;
}
int main()
{
int n,m;scanf("%d%d",&n,&m);
for(int i=0,x;i<n;i++)
{
scanf("%d",&x);
a[x]=mod-4;
}
a[0]=1;
int len=1;while(len<=m)len<<=1;
pol_sqrt(len,a,b);
++b[0];
pol_inv(len,b,c);
for(int i=1;i<=m;i++)printf("%lld\n",c[i]*2%mod);
return 0;
}
/******************** ********************/

Codeforces Round #250 (Div. 1)E. The Child and Binary Tree的更多相关文章

  1. Codeforces Round #250 (Div. 1) D. The Child and Sequence 线段树 区间取摸

    D. The Child and Sequence Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest ...

  2. Codeforces Round #250 (Div. 1) B. The Child and Zoo 并查集

    B. The Child and Zoo Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/438/ ...

  3. Codeforces Round #250 (Div. 1) A. The Child and Toy 水题

    A. The Child and Toy Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/438/ ...

  4. Codeforces Round #250 (Div. 1) D. The Child and Sequence (线段树)

    题目链接:http://codeforces.com/problemset/problem/438/D 给你n个数,m个操作,1操作是查询l到r之间的和,2操作是将l到r之间大于等于x的数xor于x, ...

  5. Codeforces Round #250 (Div. 2)—A. The Child and Homework

         好题啊,被HACK了.曾经做题都是人数越来越多.这次比赛 PASS人数 从2000直掉 1000人  被HACK  1000多人! ! ! ! 没见过的科技啊 1 2 4 8 这组数 被黑的 ...

  6. Codeforces Round #250 (Div. 1) D. The Child and Sequence(线段树)

    D. The Child and Sequence time limit per test 4 seconds memory limit per test 256 megabytes input st ...

  7. Codeforces Round #250 (Div. 1) D. The Child and Sequence

    D. The Child and Sequence time limit per test 4 seconds memory limit per test 256 megabytes input st ...

  8. Codeforces Round #250 (Div. 2) D. The Child and Zoo 并查集

    D. The Child and Zoo time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

  9. Codeforces Round #250 (Div. 2)B. The Child and Set 暴力

    B. The Child and Set   At the children's day, the child came to Picks's house, and messed his house ...

随机推荐

  1. html 之 td valign 和 align

    1.align属性趋向于左右对齐,其值包含:left.right.center 2.valign属性趋向于垂直对齐,其值包含:top.bottom.middle.baseline 兼容性 在 HTML ...

  2. BZOJ2956: 模积和

    Description 求∑∑((n mod i)*(m mod j))其中1<=i<=n,1<=j<=m,i≠j. Input 第一行两个数n,m. Output 一个整数表 ...

  3. Android中EditText焦点问题

    https://www.jianshu.com/p/3d31d681f4bc 问题:当EditText失去焦点时做内容校验 场景:用户编辑EditText将内容清空,当点击空白地方时关闭软键盘,同时校 ...

  4. springBoot 学习(总)

    springBoot有个中文文档网址,应该是持续更新的. 别的资料 http://tengj.top/2017/02/26/springboot1/     http://412887952-qq-c ...

  5. Vue.extend提供自定义组件的构造器

    Vue.extend 返回的是一个“扩展实例构造器”,也就是预设了部分选项的Vue实例构造器.经常服务于Vue.component用来生成组件,可以简单理解为当在模板中遇到该组件名称作为标签的自定义元 ...

  6. js捕获错误

    文: http://www.jb51.net/article/78764.htm 用window.onerror捕获并上报Js错误的方法 前两天有个2048游戏的用户反馈说,打开游戏后不能玩儿,只有一 ...

  7. SpringBoot学习(二)

    spring-boot-starter-parent Maven的用户可以通过继承spring-boot-starter-parent项目来获得一些合理的默认配置.这个parent提供了以下特性: 默 ...

  8. VR外包AR外包公司(虚拟现实外包公司)承接虚拟现实项目开发(企业、教育、游戏)

    VR外包AR外包公司(虚拟现实外包公司)承接虚拟现实项目开发(企业.教育.游戏) 可公对公签正规合同,开发票. 我们是北京的公司.专业团队,成员为专业 VR/AR 产品公司一线开发人员,有大型产品开发 ...

  9. DLL.LoadLibrary失败(126)

    1.LoadLibrary 返回 NULL,GetLastError 显示的是 错误码126,msdn上是这样的: ERROR_MOD_NOT_FOUND 126 (0x7E) The specifi ...

  10. java开发手册(阿里巴巴)——编程规约(部分)

    (一)命名风格 3. [强制]类名使用 UpperCamelCase 风格,但以下情形例外:DO / BO / DTO / VO / AO / PO / UID 等. 正例:MarcoPolo / U ...