Codeforces Round #250 (Div. 1)E. The Child and Binary Tree
题意:有一个集合,求有多少形态不同的二叉树满足每个点的权值都属于这个集合并且总点权等于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的更多相关文章
- 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 ...
- 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/ ...
- 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/ ...
- 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, ...
- Codeforces Round #250 (Div. 2)—A. The Child and Homework
好题啊,被HACK了.曾经做题都是人数越来越多.这次比赛 PASS人数 从2000直掉 1000人 被HACK 1000多人! ! ! ! 没见过的科技啊 1 2 4 8 这组数 被黑的 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- HTTP协议请求类型介绍
HTTP协议中共定义了八种方法或者叫"动作"来表明对Request-URI指定的资源的不同操作方式,具体介绍如下: OPTIONS: 返回服务器针对特定资源所支持的HTTP请求方法 ...
- [转] Java中的final、static、this、super
final 关键字 final关键字主要用在三个地方:变量.方法.类. 对于一个final变量,如果是基本数据类型的变量,则其数值一旦在初始化之后便不能更改:如果是引用类型的变量,则在对其初始化之后便 ...
- Bytom矿池接入协议指南
矿机配置 https://gist.github.com/HAOYUatHZ/a47400bde4a138825faef415387b532c 固件升级 https://service.bitmain ...
- 自定义Exception:MVC抛出自定义异常,并以Json方式返回
相关链接 优点: 可以统一处理所有页面的异常,对所有需要返回json数据的异常,都用同样的方法throw new DVMException().页面展示,controller的错误处理方式一样 节省编 ...
- JVM 及 垃圾回收机制原理
JVM Java 虚拟机 Java 虚拟机(Java virtual machine,JVM)是运行 Java 程序必不可少的机制.JVM实现了Java语言最重要的特征:即平台无关性.原理:编译后的 ...
- JavaScript 调试常见报错以及原因
JavaScript 调试常见报错以及原因 测试环境 chrome 版本 66.0.3359.170(正式版本) (64 位) TypeError 类型错误 不是操作符所接受的数据类型. //---- ...
- NPOI导入导出EXCEL通用类,可直接使用在WinForm项目中
由于XSSFWorkbook类型的Write方法限制,Write完成后就自动关闭流数据,所以无法很好的支持的Web模式,网上目前也未找到好的解决方案. 注意:若直接使用在WinForm项目中,必需先下 ...
- Python pycharm 常用快捷键
快捷键 1.编辑(Editing) Ctrl + Space 基本的代码完成(类.方法.属性) Ctrl + Alt + Space 快速导入任意类 Ctrl + Shift + Enter 语句完成 ...
- React native 之android的图标和启动图片
哎哎呀呀,上篇说到了react native的IOS的图标和启动图片的设置,其实最主要的是尺寸!相应的尺寸设定好了以后就不会报错了! ok~这篇说的是React native的android的图标和启 ...
- java中\r与\n的区别
\r : return 到当前行的最左边. \n: newline 向下移动一行,并不移动左右. Linux中\n表示回车+换行: Windows中\r\n表示回车+换行. 测试了一下,在java,w ...