Gnutella Chessmaster

Topic
This is a Muslim practice formulas do not need to push.
First, we put black and white chessboard stained, get two new board, then get on the board number two respectively in the program \ (r, R \) and then rolled up just fine.
Observation available checkerboard \ (B_1 = (1,1,3,3, \ cdots), B_2 = (2,2,4,4, \ cdots) \) , the number of lines are \ (n, n-1 \ ) .
For (B_1 \) \ Application Goldman-Joichi-White theorem \ (\ sum \ limits_ {i = 0} ^ nr_ix ^ {\ underline {ni}} = x ^ {\ lfloor \ frac n2 \ rfloor} (x + . 1) ^ {\ lceil \ FRAC N2 \ rceil} \) .
For (B_2 \) \ Application Goldman-Joichi-White theorem \ (\ sum \ limits_ {i = 0} ^ {n-1} R_ix ^ {\ underline {ni}} = (x + 2) ^ {\ lfloor \ FRAC N2 \ rfloor} (X +. 1) ^ {\ lceil \ FRAC N2 \-rceil. 1} \) .
If we turn directly to the general decline in the power of the polynomial polynomial you can get a \ (O (n \ log ^ 2n) \) spicy chicken practice.
We observe the process of general decline in polynomial transfer power polynomial: multi-point evaluation, IFDT.
Wherein IFDT is rewound to a variant EGF\ (E ^ {-} X \) , complexity \ (O (n-\ log n-) \) , the constant is also very good.
And we obviously do not need multi-point evaluation, the right of the obvious can \ (O (n \ log n ) \) fast multi-point evaluation, the constant is more excellent than the above IFDT.
So that we can get two polynomials a power drop, reverse what you can get \ (r, R \) , and then rolled up just fine.

#include<cstdio>
#include<cctype>
#include<algorithm>
#include<cstring>
using std::reverse;
using u64=unsigned long long;
const int N=262150,P=998244353;
namespace IO
{
    char ibuf[(1<<21)+1],obuf[(1<<21)+1],st[15],*iS,*iT,*oS=obuf,*oT=obuf+(1<<21);
    char Get(){return (iS==iT? (iT=(iS=ibuf)+fread(ibuf,1,(1<<21)+1,stdin),(iS==iT? EOF:*iS++)):*iS++);}
    void Flush(){fwrite(obuf,1,oS-obuf,stdout),oS=obuf;}
    void Put(char x){*oS++=x;if(oS==oT)Flush();}
    int read(){int x=0,c=Get();while(!isdigit(c))c=Get();while(isdigit(c))x=x*10+c-48,c=Get();return x;}
    void write(int x){int top=0;if(!x)Put('0');while(x)st[++top]=(x%10)+48,x/=10;while(top)Put(st[top--]);Put(' ');}
}using namespace IO;
void swap(int&x,int&y){x^=y^=x^=y;}
int mod(int x){return x+(x>>31&P);}
int mul(int a,int b){return (u64)a*b%P;}
int pow(int a,int k){int r=1;for(;k;k>>=1,a=mul(a,a))if(k&1)r=mul(a,r);return r;}
int w[N],ifac[N],r[N],lim;
void init(int n)
{
    int l=33-__builtin_clz(n),g(pow(3,(P-1)>>l));
    lim=1<<l,ifac[0]=w[lim>>1]=1,--l;
    for(int i=1;i<lim;++i) r[i]=(r[i>>1]>>1)|((i&1)<<l);
    for(int i=1;i<=n;++i) ifac[i]=mul(ifac[i-1],pow(i,P-2));
    for(int i=(lim>>1)+1;i<lim;++i) w[i]=mul(w[i-1],g);
    for(int i=(lim>>1)-1;i;--i) w[i]=w[i<<1];
    return ;
}
void NTT(int*a,int f)
{
    if(!~f) reverse(a+1,a+lim);
    static u64 t[N];
    for(int i=0;i<lim;++i) t[r[i]]=a[i];
    for(int i=1;i<lim;i<<=1) for(int j=0,d=i<<1;j<lim;j+=d) for(int k=0,x;k<i;++k) x=t[i|j|k]*w[i|k]%P,t[i|j|k]=t[j|k]+P-x,t[j+k]+=x;
    for(int i=0;i<lim;++i) a[i]=t[i]%P;
    if(!~f) for(int i=0,p=(P-(P-1)/lim);i<lim;++i) a[i]=mul(a[i],p);
}
int e[N],f[N],g[N];
int main()
{
    int n=read();
    if(n==1) return !printf("1");
    init(n);
    for(int i=0;i<=n;++i) e[i]=i&1? P-ifac[i]:ifac[i];
    for(int i=1;i<=n;++i) f[i]=mul(mul(pow(i,n>>1),pow(i+1,(n+1)/2)),ifac[i]);
    for(int i=0;i<n;++i) g[i]=mul(mul(pow(i+2,n>>1),pow(i+1,(n-1)/2)),ifac[i]);
    NTT(e,1),NTT(f,1),NTT(g,1);
    for(int i=0;i<lim;++i) f[i]=mul(f[i],e[i]),g[i]=mul(g[i],e[i]);
    NTT(f,-1),NTT(g,-1),memset(f+n+1,0,(lim-n-1)<<2),memset(g+n,0,(lim-n)<<2),reverse(f,f+n+1),reverse(g,g+n),NTT(f,1),NTT(g,1);
    for(int i=0;i<lim;++i) f[i]=mul(f[i],g[i]);
    NTT(f,-1);
    for(int i=1;i<n*2;++i) printf("%d ",f[i]);
}

Block quote

Guess you like

Origin www.cnblogs.com/cjoierShiina-Mashiro/p/12169039.html