Portal
OK...... This many-item open root Template ... And I have no idea how the big guys put the formula out of this problem ...
First, the problem requires polynomial open root and polynomial inversion. Polynomial inversion look here, here, here's a polynomial open root
Polynomial root: Known polynomial $a$, to find polynomial $b$ meet $a^2\equiv b\pmod{x^n}$ (and polynomial inversion as here need to take the mold, otherwise $a$ may have countless items)
Suppose we have already found a $ A ' ^2\equiv b\pmod{x^n}$, consider how to calculate $a^2\equiv b\pmod{x^{2n}}$
First of all there must be $a^2\equiv b\pmod{x^n}$
Then subtract $ $A ' ^2-a^2\equiv 0\pmod{x^n}$$
$$ (a '-a) (a ' +a) \equiv 0\pmod{x^n}$$
We assume $ A '-a\equiv 0\pmod{x^n}$, then both sides squared $ $A ' ^2-2a ' a+a^2\equiv 0\pmod{x^{2n}}$$
(The reason for the modulus change after the square can be seen in my polynomial for the inverse of that article, there are written)
And because $a^2\equiv b\pmod{x^{2n}}$, substituting $ $A ' ^2-2a ' a+b\equiv 0\pmod{x^{2n}}$$
$ $A \equiv\frac{a ' ^2-b}{2a '}\pmod{x^{2n}}$$
So this is just a recursive calculation.
And then the polynomial formula is here.
Let's talk about how this is done.
First of all, I do not know how to think of the structure of the build function, $C =\sum_{i=1}^{lim}s_ix^i$, where $s_i$ indicates whether $i$ has occurred in the collection, and then set a $f_k$ that the weight is $k$ when the answer
Because a binary tree can be composed of the root node, the left and right sub-tree (the left and the sub-tree can be empty)
Then there is the following relationship $ $F _k=1+\sum_{i=1}^ks_i\sum_{j=0}^{k-i}f_jf_{i-j-k}$$
And then I don't know how to see it. This is a convolution form, that is, $ $F =1+c*f*f$$ (here $*$ is polynomial multiplication)
Think of it as a unary two-time equation solution, get $ $F =\frac{1\pm \sqrt{1-4c}}{2c}=\frac{2}{1\pm\sqrt{1-4c}}$$
Then because $f_0=1,c_0=0$, so the symbol is positive, that is, $ $F =\frac{2}{1+\sqrt{1-4c}}$$
Well, it would be nice to take the polynomial open root and the polynomial inversion board.
1 //Minamoto2#include <iostream>3#include <cstdio>4#include <algorithm>5 #defineSwap (x, y) (x^=y,y^=x,x^=y)6 #defineMul (x, y) (1ll*x*y%p)7 #defineAdd (x, y) (x+y>=p?x+y-p:x+y)8 #defineDec (x, y) (x-y<0?x-y+p:x-y)9 using namespacestd;Ten #defineGetc () (p1==p2&& (p2= (p1=buf) +fread (Buf,1,1<<21,stdin), P1==P2)? eof:*p1++) One Charbuf[1<< +],*p1=buf,*p2=buf; AInlineintRead () { - #defineNum ch-' 0 ' - CharChBOOLflag=0;intRes; the while(!isdigit (ch=getc ())) -(ch=='-') && (flag=true); - for(Res=num;isdigit (Ch=getc ()); res=res*Ten+num); -(flag) && (res=-res); + #undefNum - returnRes; + } A Charsr[1<< +],z[ -];intk=-1, Z; atInlinevoidOt () {fwrite (SR),1, K +1, stdout), k=-1;} -InlinevoidPrintintx) { - if(k>1<< -) Ot ();if(x<0) sr[++k]= $, x=-x; - while(z[++z]=x%Ten+ -, x/=Ten); - while(Sr[++k]=z[z],--z); sr[++k]='\ n'; - } in Const intn=500005, p=998244353, g=3, inv2=499122177; -InlineintKsmintAintb) { to intres=1; + while(b) { - if(b&1) res=Mul (res,a); theA=mul (a,a), b>>=1; * } $ returnRes;Panax Notoginseng } - intN,m,r[n],a[n],b[n],c[n],d[n],o[n],d[n],c[n]; the voidNTT (int*a,intTypeintLen) { + intlimit=1, l=0; A while(Limit<len) limit<<=1,++l; the for(intI=0; i<limit;++i) +R[i]= (r[i>>1]>>1)| ((i&1) << (l1)); - for(intI=0; i<limit;++i) $ if(i<R[i]) swap (a[i],a[r[i]); $ for(intMid=1; mid<limit;mid<<=1){ - intr=mid<<1, Wn=ksm (G, P-1)/R); o[0]=1; - for(intj=1; j<mid;++j) O[j]=mul (o[j-1],wn); the for(intj=0; j<limit;j+=R) { - for(intk=0; k<mid;++k) {Wuyi intX=a[j+k],y=mul (o[k],a[j+k+mid]); theA[j+k]=add (x, y), a[j+k+mid]=Dec (x, y); - } Wu } - } About if(type==-1){ $Reverse (A +1, A +limit); - for(intI=0, Inv=ksm (limit,p-2); i<limit;++i) -a[i]=Mul (A[I],INV); - } A } + voidINV (int*a,int*b,intLen) { the if(len==1)return(void) (b[0]=KSM (a[0],p-2)); -INV (a,b,len>>1); $ for(intI=0; i<len;++i) a[i]=a[i],b[i]=B[i]; theNTT (A,1,len<<1), NTT (B,1,len<<1); the for(intI=0, L= (len<<1); i<l;++i) a[i]=Mul (Mul (A[i],b[i]), b[i]); theNTT (a,-1,len<<1); the for(intI=0; i<len;++i) B[i]=dec (1ll* (b[i]<<1)%p,a[i]); - for(intI=0, L= (len<<1); i<l;++i) a[i]=b[i]=0; in } the voidSQRT (int*a,int*b,intLen) { the if(len==1)return(void) (b[0]=a[0]); AboutSQRT (a,b,len>>1); the for(intI=0; i<len;++i) c[i]=A[i]; the INV (B,d,len); theNTT (C,1,len<<1), NTT (D,1,len<<1); + for(intI=0,l=len<<1; i<l;++i) d[i]=Mul (D[i],c[i]); -NTT (d,-1,len<<1); the for(intI=0; i<len;++i) b[i]=Mul (Add (B[i],d[i]), inv2);Bayi for(intI=0, L= (len<<1); i<l;++i) c[i]=d[i]=0; the } the intMain () { - //freopen ("testdata.in", "R", stdin); -N=read (), m=read (); the for(intI=1, X;i<=n;++i) X=read (), + +D[x]; the intLen for(len=1; len<=m;len<<=1); the for(intI=1; i<len;++i) d[i]= (-4*D[I]+P)%P; the++d[0]; - Sqrt (D,c,len); the for(intI=0; i<len;++i) d[i]=0; thec[0]=add (c[0],1); the INV (C,d,len);94 for(intI=0; i<=m;++i) d[i]=Add (D[i],d[i]); the for(intI=1; i<=m;++i) print (d[i]); the Ot (); the return 0;98}
cf438e the Child and Binary Tree (Generate function + polynomial open + polynomial inversion)