• 【LOJ #2409】【THUPC 2017】—小L的计算题(多项式Ln+生成函数)


    传送门

    先推一波式子
    构造生成函数OGFOGF
    f(x)=i=0fixi=i=0j=1najixi=j=1ni=0(ajx)i=j=1n11ajx f(x)= sum_{i=0}^{infty}f_ix^i \ = sum_{i=0}^{infty}sum_{j=1}^{n}a_j^ix^i \ =sum_{j=1}^{n}sum_{i=0}^{infty}(a_jx)^i \ =sum_{j=1}^{n}frac{1}{1-a_jx}

    这个东西也不好直接求
    继续化

    f(x)=i=1n1ajx1ajx=nxi=1naj1ajx f(x)=sum_{i=1}^{n}1-frac{-a_jx}{1-a_jx}\ =n- xsum_{i=1}^{n}frac{-a_j}{1-a_jx}

    考虑对1ajx1-a_jx求导就是aj-a_j
    所以后面一坨东西可以化成LnLn求导得到的

    f(x)=nx(i=1nLn(1ajx))=nx[Ln(i=1n(1ajx))] f(x)=n-x(sum_{i=1}^{n}Ln(1-a_jx))' \ =n-x[Ln(prod_{i=1}^n(1-a_jx))]'

    分治nttntt后做LnLn即可

    aa读入时先取模

    #include<bits/stdc++.h>
    using namespace std;
    #define gc getchar
    inline int read(){
    	char ch=gc();
    	int res=0,f=1;
    	while(!isdigit(ch))f^=ch=='-',ch=gc();
    	while(isdigit(ch))res=(res+(res<<2)<<1)+(ch^48),ch=gc();
    	return f?res:-res;
    }
    #define re register
    #define pb push_back
    #define cs const
    #define pii pair<int,int>
    #define fi first
    #define se second
    #define ll long long
    cs int mod=998244353,G=3;
    inline int add(int a,int b){return (a+=b)>=mod?a-mod:a;}
    inline void Add(int &a,int b){(a+=b)>=mod?(a-=mod):0;}
    inline int dec(int a,int b){return (a-=b)<0?a+mod:a;}
    inline void Dec(int &a,int b){(a-=b)<0?(a+=mod):0;}
    inline int mul(int a,int b){return 1ll*a*b>=mod?1ll*a*b%mod:a*b;}
    inline void Mul(int &a,int b){a=mul(a,b);}
    inline int ksm(int a,int b,int res=1){
    	for(;b;b>>=1,a=mul(a,a))(b&1)&&(res=mul(res,a));return res;
    }
    inline void chemx(ll &a,ll b){a<b?a=b:0;}
    inline void chemn(int &a,int b){a>b?a=b:0;}
    cs int N=(1<<20)|1,C=21;
    #define poly vector<int>
    #define bg begin
    poly w[C+1];
    inline void init_w(){
    	for(int i=1;i<=C;i++)w[i].resize(1<<(i-1));
    	int wn=ksm(G,(mod-1)/(1<<C));
    	w[C][0]=1;
    	for(int i=1;i<(1<<(C-1));i++)w[C][i]=mul(w[C][i-1],wn);
    	for(int i=C-1;i;i--)
    	for(int j=0;j<(1<<(i-1));j++)
    	w[i][j]=w[i+1][j<<1];
    } 
    int rev[N<<1],inv[N<<1];
    inline void init_rev(int lim){
    	for(int i=0;i<lim;i++)rev[i]=(rev[i>>1]>>1)|((i&1)*(lim>>1));
    }
    inline void ntt(poly &f,int lim,int kd){
    	for(int i=0;i<lim;i++)if(i>rev[i])swap(f[i],f[rev[i]]);
    	for(int a0,a1,mid=1,l=1;mid<lim;mid<<=1,l++)
    	for(int i=0;i<lim;i+=(mid<<1))
    	for(int j=0;j<mid;j++)
    	a0=f[i+j],a1=mul(f[i+j+mid],w[l][j]),f[i+j]=add(a0,a1),f[i+j+mid]=dec(a0,a1);
    	if(kd==-1){
    		reverse(f.bg()+1,f.bg()+lim);
    		for(int i=0;i<lim;i++)Mul(f[i],inv[lim]);
    	}
    }
    inline poly operator *(poly a,poly b){
    	int deg=a.size()+b.size()-1,lim=1;
    	if(deg<=128){
    		poly c(deg,0);
    		for(int i=0;i<a.size();i++)
    		for(int j=0;j<b.size();j++)
    		Add(c[i+j],mul(a[i],b[j]));
    		return c;
    	}
    	while(lim<deg)lim<<=1;
    	init_rev(lim);
    	a.resize(lim),b.resize(lim);
    	ntt(a,lim,1),ntt(b,lim,1);
    	for(int i=0;i<lim;i++)Mul(a[i],b[i]);
    	ntt(a,lim,-1),a.resize(deg);
    	return a;
    }
    inline int F(cs poly &f,int x){
    	int res=0;
    	for(int i=0,t=1;i<f.size();i++,Mul(t,x))Add(res,mul(f[i],t));
    	return res;
    }
    inline poly deriv(poly f){
    	for(int i=0;i<f.size()-1;i++)f[i]=mul(f[i+1],i+1);
    	f.pop_back();return f;
    }
    inline poly integ(poly f){
    	f.pb(0);
    	for(int i=f.size()-1;i;i--)f[i]=mul(f[i-1],inv[i]);
    	f[0]=0;return f;
    }
    inline void init_inv(){
    	inv[0]=inv[1]=1;
    	for(int i=2;i<N*2;i++)inv[i]=mul(mod-mod/i,inv[mod%i]);
    }
    inline poly Inv(poly a,int deg){
    	poly c,b(1,ksm(a[0],mod-2));
    	for(int lim=4;lim<(deg<<2);lim<<=1){
    		c=a,c.resize(lim>>1);
    		init_rev(lim);
    		b.resize(lim),ntt(b,lim,1);
    		c.resize(lim),ntt(c,lim,1);
    		for(int i=0;i<lim;i++)Mul(b[i],dec(2,mul(b[i],c[i])));
    		ntt(b,lim,-1),b.resize(lim>>1);
    	}b.resize(deg);return b;
    }
    inline poly Ln(poly f,int deg){
    	f=integ(deriv(f)*Inv(f,deg)),f.resize(deg);
    	return f;
    }
    poly f[N<<2];
    #define lc (u<<1)
    #define rc ((u<<1)|1)
    #define mid ((l+r)>>1)
    inline void build(int u,int l,int r,int *v){
    	if(l==r){f[u].clear();f[u].pb(1),f[u].pb(mod-v[l]);return;}
    	build(lc,l,mid,v),build(rc,mid+1,r,v);
    	f[u]=f[lc]*f[rc];
    }
    #undef lc
    #undef rc
    #undef mid
    int n,a[N];
    int main(){
    	#ifdef Stargazer
    	freopen("1.in","r",stdin);
    	#endif
    	int T=read();
    	init_inv();
    	init_w();
    	while(T--){
    		n=read();
    		for(int i=1;i<=n;i++)a[i]=read()%mod;
    		build(1,1,n,a);
    		poly res=Ln(f[1],n+1);
    		res=deriv(res);
    		res.pb(0);
    		for(int i=res.size()-1;i;i--)res[i]=mod-res[i-1];
    		res[0]=n;
    		int ans=0;
    		for(int i=1;i<res.size();i++)ans^=res[i];
    		cout<<ans<<'
    ';
    	}
    }
    
  • 相关阅读:
    运行级别和root密码找回
    磁盘情况查询
    linux磁盘分区、挂载
    三、本地负载均衡器与openfeign声明式客户端
    二、Nacos服务注册与发现
    一、微服务架构演变过程
    shell工具
    Netty概述
    垃圾回收概述及算法
    执行引擎
  • 原文地址:https://www.cnblogs.com/stargazer-cyk/p/12328689.html
Copyright © 2020-2023  润新知