BZOJ3625: [Codeforces Round #250] children and two fork trees

Source: Internet
Author: User

Description

Our children like computer science very much, and especially like binary trees.
Consider a sequence c[1],c[2],..., c[n] that contains n mutually positive integers. If a weighted binary tree satisfies the weights of all its vertices in the set {c[1],c[2],..., c[n]}, our children will call them God Ben. And he thinks that the weight of a tree with a bit of weight is the sum of all its vertex weights.
Given an integer m, can you calculate the number of divine Ben binary trees with a weight of s for any of the S (1<=s<=m)? Please refer to the sample to better understand what two binary trees will be considered different.
We just need to know the answer about the value of 998244353 (7*17*2^23+1, a prime number) after modulo.

Input

The first line has 2 integers n,m (1<=n<=10^5; 1<=m<=10^5).
The second line has n spaces separated by a different integer c[1],c[2],..., c[n] (1<=c[i]<=10^5).

Output

Outputs m rows with one integer per line. The first line should contain the total number of divine Ben binary trees with the right value just I. Please output the answer about 998244353 (=7*17*2^23+1, a prime number) after modulo the result.

Sample InputExample One:
2 3
1 2
Example two:
3 10
9 4 3
Example three:
5 10
13 10 6) 4 15
Sample OutputExample one:
1
3
9
Example two:
0
0
1
1
0
2
4
2
6
15
Example three:
0
0
0
1
0
1
0
2
0
5
HINT

For the first example, there are 9 divine Ben binary trees with a weight of exactly 3:

This week I learned to learn about polynomial and generative functions. Set F[x] to represent the number of two forks of the X, then f[i]=∑c[j]*f[k]*f[i-j-k] set f[x] The generating function for f,c[x] is C. The f=f^2*c+1 is then applied to the root formula to derive f=2/(1+-sqrt (1-4C)), because the polynomial reversible condition is the constant term reversible, so f=2/(1+sqrt (1-4C)). Then it is the polynomial that asks for the inverse open square.
#include <cstdio> #include <cctype> #include <queue> #include <cstring> #include <algorithm > #define REP (i,s,t) for (int. i=s;i<=t;i++) #define DWN (I,S,T) for (int. i=s;i>=t;i--) #define REN for (int i=first[x ];i;i=next[i]) using namespace Std;const int Buffersize=1<<16;char Buffer[buffersize],*head,*tail;inline Char Getchar () {if (head==tail) {int l=fread (Buffer,1,buffersize,stdin); tail= (Head=buffer) +l;} return *head++;}    inline int read () {int X=0,f=1;char c=getchar (); for (;!    IsDigit (c); C=getchar ()) if (c== '-') f=-1;    for (; IsDigit (c); C=getchar ()) x=x*10+c-' 0 '; return x*f;} typedef long LONG ll;const int p=998244353;const int maxn=300010;const int g=3;const ll Inv2=499122177;ll Pow (ll n,ll m) { ll ans=1;for (; m;m>>=1, (n*=n)%=p) if (m&1) (ans*=n)%=p;return ans;} int wn[20];void NTT (int* a,int len,int t) {int J=len>>1,c=0;rep (i,1,len-2) {if (i<j) swap (a[i],a[j]); int k=len& Gt;>1;while (J>=k) j-=k,k>>=1;j+=k;} for (int i=2;i<=len;i< <=1) {c++;for (int j=0;j<len;j+=i) {int w=1;for (int k=j;k<j+ (i>>1); k++) {int u=a[k],t= (LL) w*a[k+ (i> >1)]%p; a[k]= (u+t)%p; a[k+ (i>>1)]= (u-t+p)%p;w= ((LL) w*wn[c])%p;}}} if (t<0) {int Inv=pow (len,p-2), Rep (i,1,len/2-1) swap (A[i],a[len-i]), Rep (i,0,len-1) a[i]= ((LL) A[I]*INV)%p;}} int t[maxn];void GETINV (int* a,int* b,int N) {if (n==1) {B[0]=pow (a[0],p-2); return;} GETINV (a,b,n>>1); int Len=n<<1;rep (i,0,n-1) t[i]=a[i],t[i+n]=0; NTT (b,len,1); NTT (t,len,1); Rep (i,0,len-1) b[i]= (LL) b[i]* ((LL) b[i]*t[i]%p+p)%p; NTT (B,LEN,-1); Rep (i,n,len-1) b[i]=0;} int revb[maxn];void getsqrt (int* a,int* b,int N) {if (n==1) {B[0]=1;return;} GETSQRT (a,b,n>>1); int Len=n<<1;rep (i,0,n-1) REVB[I]=0;GETINV (b,revb,n); Rep (i,0,n-1) T[i]=A[i],T[i+n]= 0; NTT (b,len,1); NTT (t,len,1); NTT (revb,len,1); Rep (i,0,len-1) b[i]= (LL) inv2* (b[i]+ (LL) t[i]*revb[i]%p)%p; NTT (B,LEN,-1); Rep (i,n,len-1) b[i]=0;} int A[maxn],b[maxn],ans[maxn];int Main () {Rep (i,1,19) Wn[i]=pow (G, (p-1)/(1<<i)); int N=read (), M=reAD (), Len=1;while (len<=m) len<<=1; A[0]=1;rep (i,0,n-1) {int x=read (); if (x<=m) a[x]-=4;if (a[x]<0) a[x]+=p;} Getsqrt (A,b,len);(++b[0])%=P;GETINV (B,ans,len), Rep (i,1,m) printf ("%d\n", ans[i]*2%p); return 0;}

  

BZOJ3625: [Codeforces Round #250] children and two fork trees

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.