QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#140272#4552. 如何优雅地求和myee100 ✓8ms4916kbC++1120.3kb2023-08-15 16:45:182023-08-15 16:45:21

Judging History

你现在查看的是最新测评结果

  • [2023-08-15 16:45:21]
  • 评测
  • 测评结果:100
  • 用时:8ms
  • 内存:4916kb
  • [2023-08-15 16:45:18]
  • 提交

answer

#include <algorithm>
#include <stdio.h>
#include <vector>
typedef long long llt;
typedef unsigned uint;typedef unsigned long long ullt;
typedef bool bol;typedef char chr;typedef void voi;
typedef double dbl;
template<typename T>bol _max(T&a,T b){return(a<b)?a=b,true:false;}
template<typename T>bol _min(T&a,T b){return(b<a)?a=b,true:false;}
template<typename T>T power(T base,T index,T mod){return((index<=1)?(index?base:1):(power(base*base%mod,index>>1,mod)*power(base,index&1,mod)))%mod;}
template<typename T>T lowbit(T n){return n&-n;}
template<typename T>T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<typename T>T lcm(T a,T b){return(a!=0||b!=0)?a/gcd(a,b)*b:(T)0;}
template<typename T>T exgcd(T a,T b,T&x,T&y){if(!b)return y=0,x=1,a;T ans=exgcd(b,a%b,y,x);y-=a/b*x;return ans;}
template<const ullt p=998244353>
class mod_ullt
{
    private:
        ullt v;
        inline ullt chg(ullt w){return(w<p)?w:w-p;}
        inline mod_ullt _chg(ullt w){mod_ullt ans;ans.v=(w<p)?w:w-p;return ans;}
    public:
        mod_ullt():v(0){}
        mod_ullt(ullt v):v(v%p){}
        bol empty(){return!v;}
        inline ullt val(){return v;}
        friend bol operator<(mod_ullt a,mod_ullt b){return a.v<b.v;}
        friend bol operator>(mod_ullt a,mod_ullt b){return a.v>b.v;}
        friend bol operator<=(mod_ullt a,mod_ullt b){return a.v<=b.v;}
        friend bol operator>=(mod_ullt a,mod_ullt b){return a.v>=b.v;}
        friend bol operator==(mod_ullt a,mod_ullt b){return a.v==b.v;}
        friend bol operator!=(mod_ullt a,mod_ullt b){return a.v!=b.v;}
        inline friend mod_ullt operator+(mod_ullt a,mod_ullt b){return a._chg(a.v+b.v);}
        inline friend mod_ullt operator-(mod_ullt a,mod_ullt b){return a._chg(a.v+a.chg(p-b.v));}
        inline friend mod_ullt operator*(mod_ullt a,mod_ullt b){return a.v*b.v;}
        friend mod_ullt operator/(mod_ullt a,mod_ullt b){return b._power(p-2)*a.v;}
        friend mod_ullt operator^(mod_ullt a,ullt b){return a._power(b);}
        inline mod_ullt operator-(){return _chg(p-v);}
        mod_ullt sqrt()
        {
            if(power(v,(p-1)>>1,p)!=1)return 0;
            mod_ullt b=1;do b++;while(b._power((p-1)>>1)==1);
            ullt t=p-1,s=0,k=1;while(!(t&1))s++,t>>=1;
            mod_ullt x=_power((t+1)>>1),e=_power(t);
            while(k<s)
            {
                if(e._power(1llu<<(s-k-1))!=1)x*=b._power((1llu<<(k-1))*t);
                e=_power(p-2)*x*x,k++;
            }
            return _min(x,-x),x;
        }
        mod_ullt inv(){return _power(p-2);}
        mod_ullt _power(ullt index){mod_ullt ans(1),w(v);while(index){if(index&1)ans*=w;w*=w,index>>=1;}return ans;}
        voi read(){v=0;chr c;do c=getchar();while(c>'9'||c<'0');do v=(c-'0'+v*10)%p,c=getchar();while(c>='0'&&c<='9');v%=p;}
        voi print()
        {
        	static chr C[20];uint tp=0;
        	ullt w=v;do C[tp++]=w%10+'0',w/=10;while(w);
        	while(tp--)putchar(C[tp]);
        }
        voi println(){print(),putchar('\n');}
        mod_ullt operator++(int){mod_ullt ans=*this;return v=chg(v+1),ans;}
    public:
        inline ullt&operator()(){return v;}
        inline mod_ullt&operator+=(mod_ullt b){return*this=_chg(v+b.v);}
        inline mod_ullt&operator-=(mod_ullt b){return*this=_chg(v+chg(p-b.v));}
        inline mod_ullt&operator*=(mod_ullt b){return*this=v*b.v;}
        mod_ullt&operator^=(ullt b){return*this=_power(b);}
        mod_ullt&operator/=(mod_ullt b){return*this=b._power(p-2)*v;}
        mod_ullt&operator++(){return v=chg(v+1),*this;}
};
template<const ullt p=998244353,const ullt g=3>
class poly_NTT
{
    public:
		typedef mod_ullt<p>modint;
        typedef std::vector<modint>modvec;
	private:
		modvec V;
	public:
		class NTT
		{
			private:
				uint n;uint*T;modint*G;
			public:
				NTT():n(0),T(NULL),G(NULL){}
				NTT(uint len)
				{
					n=1;while(n<len)n<<=1;
                    T=new uint[n],G=new modint[n],T[0]=0,G[0]=1;
					for(uint i=1;i<n;i++)T[i]=((i&1)?n|T[i>>1]:T[i>>1])>>1;
                    modint w=power(g,(p-1)/n,p),*End=G+n;
                    for(modint*_G=G+1;_G<End;_G++)*_G=_G[-1]*w;
				}
				~NTT(){if(T!=NULL)delete[]T,delete[]G,T=NULL,G=NULL;}
				inline uint size(){return n;}
				voi bzr(uint len)
				{
					n=1;while(n<len)n<<=1;
                    if(T!=NULL)delete[]T,delete[]G;
                    T=new uint[n],G=new modint[n],T[0]=0,G[0]=1;
					for(uint i=1;i<n;i++)T[i]=((i&1)?n|T[i>>1]:T[i>>1])>>1;
                    modint w=power(g,(p-1)/n,p),*End=G+n;
                    for(modint*_G=G+1;_G<End;_G++)*_G=_G[-1]*w;
				}
				voi ntt(modvec &x,bol op)
				{
					if(x.size()<n)x.resize(n);
                    for(uint i=0;i<n;i++)if(T[i]<i)std::swap(x[i],x[T[i]]);
					for(uint i=1;i<n;i<<=1)for(uint j=0;j<n;j+=i<<1)
					{
						modint*w=G;
						for(uint k=0;k<i;k++,w+=n/(2*i))
						{
							modint t=x[i+j+k]*(*w);
							x[i+j+k]=x[j+k]-t,x[j+k]+=t;
						}
					}
					if(op)
					{
						for(uint i=1;i*2<n;i++)std::swap(x[i],x[n-i]);
						modint t=modint(n).inv();for(uint i=0;i<n;i++)x[i]*=t;
					}
				}
				inline modint Omega(uint n){return G[n%size()];}
				NTT&operator=(NTT b)
				{
					if(T!=NULL)delete[]T,delete[]G,T=NULL,G=NULL;
					if(b.T==NULL)return*this;
					T=new uint[n],G=new modint[n=b.n];
					for(uint i=0;i<n;i++)T[i]=b.T[i],G[i]=b.G[i];
					return*this;
				}
		};
		class DIFDIT
		{
			private:
				uint n;modint*G;
			public:
				DIFDIT():n(0),G(NULL){}
				DIFDIT(uint len)
				{
					n=1;while(n<len)n<<=1;
                    G=new modint[n],G[0]=1;
                    modint w=power(g,(p-1)/n,p),*End=G+n;
                    for(modint*_G=G+1;_G<End;_G++)*_G=_G[-1]*w;
				}
				~DIFDIT(){if(G!=NULL)delete[]G,G=NULL;}
				inline uint size(){return n;}
				voi bzr(uint len)
				{
					n=1;while(n<len)n<<=1;
                    if(G!=NULL)delete[]G;
                    G=new modint[n],G[0]=1;
                    modint w=power(g,(p-1)/n,p),*End=G+n;
                    for(modint*_G=G+1;_G<End;_G++)*_G=_G[-1]*w;
				}
				voi dif(modvec &x)
				{
					if(x.size()<n)x.resize(n);
					for(uint i=n>>1;i;i>>=1)for(uint j=0;j<n;j+=i<<1) 
					{
						modint*w=G;
						for(uint k=0;k<i;k++,w+=n/(2*i))
						{
							modint u=x[j+k],t=x[i+j+k];
							x[j+k]=u+t,x[i+j+k]=(u-t)*(*w);
						}
					}
				}
				voi dit(modvec &x)
				{
					if(x.size()<n)x.resize(n);
					for(uint i=1;i<n;i<<=1)for(uint j=0;j<n;j+=i<<1)
					{
						modint*w=G;
						for(uint k=0;k<i;k++,w+=n/(2*i))
						{
							modint t=x[i+j+k]*(*w);
							x[i+j+k]=x[j+k]-t,x[j+k]+=t;
						}
					}
					for(uint i=1;i*2<n;i++)std::swap(x[i],x[n-i]);
					modint t=modint(n).inv();for(uint i=0;i<n;i++)x[i]*=t;
				} 
				DIFDIT&operator=(DIFDIT b)
				{
					if(G!=NULL)delete[]G,G=NULL;
					if(b.G==NULL)return*this;
					G=new modint[n=b.n];
					for(uint i=0;i<n;i++)G[i]=b.G[i];
					return*this;
				}
		};
	public:
		poly_NTT(){}
		poly_NTT(uint n){V.resize(n);}
		poly_NTT(modvec V):V(V){}
		inline voi bzr(){V.clear();}
		inline voi push(modint v){V.push_back(v);}
		inline voi pop(){V.pop_back();}
		inline voi cut_zero(){while(!V.empty()&&V.back().empty())V.pop_back();}
		inline voi chg_siz(uint n){V.resize(n);}
		inline voi chg_deg(uint n){V.resize(n+1);}
		inline bol empty(){return cut_zero(),V.empty();}
		inline uint size(){return V.size();}
		inline uint deg(){return V.size()-1;}
		inline modint val(uint n){return(n<size())?V[n]:0;}
        inline modvec GET(){return V;}
        poly_NTT reverse()
        {
            poly_NTT ans;for(uint i=size()-1;~i;i--)ans.push(V[i]);
            return ans;
        }
		friend poly_NTT operator+(poly_NTT a,poly_NTT b)
		{
			if(a.size()<b.size())a.chg_siz(b.size());
			for(uint i=0;i<b.size();i++)a[i]+=b[i];
			a.cut_zero();return a;
		}
		friend poly_NTT operator+(poly_NTT a,modint v)
		{
			if(!a.size())a.chg_siz(1);
			a[0]+=v;return a;
		}
		friend poly_NTT operator+(modint v,poly_NTT a)
		{
			if(!a.size())a.chg_siz(1);
			a[0]+=v;return a;
		}
		friend poly_NTT operator-(poly_NTT a){return a*modint(p-1);}
		friend poly_NTT operator-(poly_NTT a,poly_NTT b)
		{
			if(a.size()<b.size())a.chg_siz(b.size());
			for(uint i=0;i<b.size();i++)a[i]-=b[i];
			a.cut_zero();return a;
		}
		friend poly_NTT operator-(poly_NTT a,modint v)
		{
			if(!a.size())a.chg_siz(1);
			a[0]-=v;return a;
		}
		friend poly_NTT operator-(modint v,poly_NTT a)
		{
			if(!a.size())a.chg_siz(1);
			a[0]-=v;return-a;
		}
		friend poly_NTT operator*(poly_NTT a,poly_NTT b)
		{
            modvec &A=a.V,&B=b.V;DIFDIT s(A.size()+B.size());
            s.dif(A),s.dif(B);for(uint i=0;i<s.size();i++)A[i]*=B[i];
            s.dit(A),a.cut_zero();return a;
		}
        friend poly_NTT operator*(poly_NTT A,modint b)
        {
            for(auto&s:A.V)s*=b;
            return A;
        }
        friend poly_NTT operator*(modint b,poly_NTT A)
        {
            for(auto&s:A.V)s*=b;
            return A;
        }
        friend poly_NTT operator<<(poly_NTT a,uint k)
        {
        	poly_NTT ans;ans.chg_siz(k);for(auto v:a.V)ans.push(v);
        	return ans;
        }
        friend poly_NTT operator>>(poly_NTT a,uint k)
        {
        	poly_NTT ans;for(uint i=k;i<a.size();i++)ans.push(a[i]);
        	return ans;
        }
        friend poly_NTT sub_mul(poly_NTT a,poly_NTT b)
        {
            uint len=(a=a.reverse()).size();
            modvec &A=a.V,&B=b.V;
            DIFDIT s(len+B.size());
            s.dif(A),s.dif(B);for(uint i=0;i<s.size();i++)A[i]*=B[i];
            s.dit(A),a.chg_siz(len),a=a.reverse();return a;
        }
        poly_NTT inv(){return inv(size());}
        poly_NTT inv(uint prec)
        {
            modvec ans;DIFDIT s;ans.push_back(V[0].inv());
            for(uint tp=1;tp<prec;tp<<=1)
            {
                modvec f(tp<<1),t=ans;
                for(uint i=0;i<(tp<<1);++i)f[i]=val(i);
                s.bzr(tp<<1),s.dif(f),s.dif(t);
                for(uint i=0;i<(tp<<1);++i)f[i]=1-f[i]*t[i];
                s.dit(f);
                for(uint i=0;i<tp;++i)f[i]=f[i+tp],f[i+tp]=0;
                s.dif(f);
                for(uint i=(tp<<1)-1;~i;--i)f[i]*=t[i];
                s.dit(f),ans.resize(tp<<1);
            	for(uint i=0;i<tp;++i)ans[i+tp]=f[i];
            }
            ans.resize(prec);return ans;
        }
        poly_NTT diff()
        {
            poly_NTT ans;for(uint i=1;i<size();i++)ans.push(i*V[i]);
            return ans;
        }
        poly_NTT inte()
        {
            if(!size())return*this;
            poly_NTT ans(size()+1);ans[1]=1;
            for(uint i=2;i<=size();i++)ans[i]=-ans[p%i]*(p/i);
            for(uint i=1;i<=size();i++)ans[i]*=V[i-1];
            return ans;
        }
        poly_NTT ln(){return ln(size());}
        poly_NTT ln(uint prec)
        {
            poly_NTT a=this->diff()*this->inv(prec);a.chg_siz(prec),a=a.inte(),a.chg_siz(prec);return a;
        }
        poly_NTT exp(){return exp(size());}
        poly_NTT exp(uint prec)
        {
            poly_NTT ans;modvec Inv;ans.push(1),Inv.push_back(1);
            for(uint tp=1;tp<prec;tp<<=1)
            {
                modvec f,ff=ans.diff().V;
                for(uint i=0;i<(tp<<1);i++)f.push_back(val(i));
                f[0]=1;DIFDIT s(tp<<2);s.dif(ans.V),s.dif(Inv);
                for(uint i=0;i<(tp<<2);i++)Inv[i]*=2-Inv[i]*ans[i];
                s.dit(Inv),Inv.resize(tp);s.dif(Inv);
                for(uint i=0;i<(tp<<2);i++)Inv[i]*=2-Inv[i]*ans[i];
                s.dit(Inv),Inv.resize(tp<<1);s.dif(Inv);s.dif(ff);
                for(uint i=0;i<(tp<<2);i++)ff[i]*=Inv[i];
                s.dit(ff);f=(f-poly_NTT(ff).inte()).V;s.dif(f);
                for(uint i=0;i<(tp<<2);i++)ans[i]*=f[i];
                s.dit(Inv),s.dit(ans.V),ans.chg_siz(tp<<1);
            }
            ans.chg_siz(prec);return ans;
        }
        friend poly_NTT operator/(poly_NTT a,poly_NTT b)
        {
            a.cut_zero(),b.cut_zero();if(a.size()<b.size())return poly_NTT();
            poly_NTT ans=a.reverse()*b.reverse().inv(a.size()-b.size()+1);
            ans.chg_siz(a.size()-b.size()+1);return ans.reverse();
        }
        friend poly_NTT operator%(poly_NTT a,poly_NTT b){return a-a/b*b;}
	public:
		inline modint&operator[](uint n){return V[n];};
        poly_NTT&operator+=(poly_NTT b)
        {
			if(size()<b.size())chg_siz(b.size());
			for(uint i=0;i<b.size();i++)V[i]+=b[i];
			cut_zero();return*this;
        }
        inline poly_NTT&operator+=(modint v)
        {
        	if(!size())chg_siz(1);
        	V[0]+=v;return*this;
        }
        poly_NTT&operator-=(poly_NTT b)
        {
			if(size()<b.size())chg_siz(b.size());
			for(uint i=0;i<b.size();i++)V[i]-=b[i];
			cut_zero();return*this;
        }
        inline poly_NTT&operator-=(modint v)
        {
        	if(!size())chg_siz(1);
        	V[0]-=v;return*this;
        }
        poly_NTT&operator*=(poly_NTT b)
        {
            modvec &A=V,&B=b.V;
            DIFDIT s(A.size()+B.size());
            s.dif(A),s.dif(B);
            for(uint i=0;i<s.size();i++)A[i]*=B[i];
            s.dit(A),cut_zero();return*this;
        }
        poly_NTT&operator*=(modint v)
        {
        	for(auto&t:V)t*=v;
			return*this;
        }
        poly_NTT&operator/=(poly_NTT b){return*this=*this/b;}
        poly_NTT&operator%=(poly_NTT b){return*this=*this%b;}
        poly_NTT&operator<<=(uint v){return*this=*this<<v;}
        poly_NTT&operator>>=(uint v){return*this=*this>>v;}
};
template<const ullt p=998244353,const ullt g=3>
class poly_eval
{
    public:
		typedef mod_ullt<p>modint;
        typedef std::vector<modint>modvec;
        typedef poly_NTT<p,g>poly;
    private:
        std::vector<poly>G,User;modvec X;
        voi mult_eval_dfs1(uint u,uint l,uint r)
        {
            if(l+1==r){G[u].push(1),G[u].push(-X[l]);return;}
            uint mid=(l+r)/2;mult_eval_dfs1(u<<1,l,mid),mult_eval_dfs1(u<<1|1,mid,r),G[u]=G[u<<1]*G[u<<1|1];
        }
        voi mult_eval_dfs2(uint u,uint l,uint r)
        {
            User.back().chg_siz(r-l);
            if(l+1==r){X[l]=User.back().val(0);return;}
            uint mid=(l+r)/2;
            User.push_back(sub_mul(User.back(),G[u<<1|1])),mult_eval_dfs2(u<<1,l,mid);
            User.back()=sub_mul(User[User.size()-2],G[u<<1]),mult_eval_dfs2(u<<1|1,mid,r);
            User.pop_back();
        }
    public:
        voi mult_eval(poly P,modvec &X)
        {
            if(X.empty())return;
            G.resize(X.size()<<2),User.clear(),this->X=X;
            mult_eval_dfs1(1,0,X.size());
            User.push_back(sub_mul(P,G[1].inv(std::max<uint>(P.size(),X.size())+1)));
            mult_eval_dfs2(1,0,X.size());
            G.clear(),User.clear(),X=this->X,this->X.clear();
        }
};
template<const ullt p=998244353,const ullt g=3>
class poly_inter
{
    public:
		typedef mod_ullt<p>modint;
        typedef std::vector<modint>modvec;
        typedef poly_NTT<p,g>poly;
        typedef poly_eval<p,g>eval;
    private:
        std::vector<poly>Lim,F,G;eval E;modvec X,H;
        voi dfs(uint l,uint r)
        {
            if(l+1==r)
            {
                F.push_back(poly()),F.back().push(H[l]),G.push_back(poly()),G.back().push(-X[l]),G.back().push(1);return;
            }
            uint mid=(l+r)>>1;dfs(l,mid),dfs(mid,r);
            F[F.size()-2]=F[F.size()-2]*G.back()+F.back()*G[G.size()-2],F.pop_back(),G[G.size()-2]*=G.back(),G.pop_back();
        }
    public:
        poly fast_inter(modvec X,modvec Y)
        {
            uint n=std::min(X.size(),Y.size());if(!n)return poly();
            X.resize(n),Y.resize(n),this->X=X;poly P;Lim.clear();
            for(uint i=0;i<n;i++)
            {
                P.bzr(),P.push(-X[i]),P.push(1);
                uint w=lowbit(i+1);while(w>>=1)P*=Lim.back(),Lim.pop_back();
                Lim.push_back(P);
            }
            P=Lim.back(),Lim.pop_back();while(Lim.size())P*=Lim.back(),Lim.pop_back();
            E.mult_eval(P.diff(),X),H.resize(n);for(uint i=0;i<n;i++)H[i]=Y[i]/X[i];
            F.clear(),G.clear(),dfs(0,n);
            poly ans=F.back();F.clear(),G.clear(),this->X.clear(),H.clear();return ans;
        }
};
template<const ullt p=998244353,const ullt g=3>
class poly_cpd
{
    public:
		typedef mod_ullt<p>modint;
        typedef std::vector<modint>modvec;
        typedef poly_NTT<p,g>poly;
        modvec Turn(std::vector<llt>QAQ)
        {
            modvec ans;
            for(uint i=0;i<QAQ.size();i++)ans.push_back((QAQ[i]%(llt)p+p)%p);
            return ans;
        }
        modint point_eval(poly P,modint x)
        {
            modint ans;
            for(uint i=P.deg();~i;i--)ans=ans*x+P[i];
            return ans;
        }
        poly z_npow(poly P,uint n)
        {
            if(P.empty())return P;
            poly ans(P.deg()*n+1);
            for(uint i=0;i<P.size();i++)ans[i*n]+=P[i];
            return ans;
        }
        poly z_npow(poly P,uint n,uint prec)
        {
            poly ans(prec);
            for(uint i=0;i<P.size()&&i*n<prec;i++)ans[i*n]+=P[i];
            return ans;
        }
        poly z_mul_k(poly P,modint k)
        {
            modint t(1);
            for(uint i=0;i<P.size();i++)P[i]*=t,t*=k;
            return P;
        }
        poly z_add_v(poly P,modint v)
        {
            uint n=P.size();if(!n)return P;
            modvec A(n),B(n);
            A[0]=1;for(uint i=1;i<n;i++)A[i]=A[i-1]*i;
            B[n-1]=A[n-1].inv();for(uint i=n-1;i;i--)B[i-1]=B[i]*i;
            poly User(n);modint w(1);
            for(uint i=0;i<n;i++)P[i]*=A[i],User[i]=w*B[i],w*=v;
            P=sub_mul(P,User),P.chg_siz(n);
            for(uint i=0;i<n;i++)P[i]*=B[i];
            return P;
        }
        poly chg_siz(poly P,uint siz){P.chg_siz(siz);return P;}
        poly PolyaInv(poly P,uint prec){return(modint(1)-P).inv(prec);}
        poly PolyaExp(poly P,uint prec)
        {
            modvec inv(prec);
            inv[1]=1;for(uint i=2;i<prec;i++)inv[i]=(p/i)*-inv[p%i];
            poly ans(prec);
            for(uint i=1;i<prec;i++)for(uint j=1;i*j<prec&&j<P.size();j++)ans[i*j]+=P[j]*inv[i];
            return ans.exp(prec);
        }
        poly PolyaInv(poly P){return PolyaInv(P,P.size());}
        poly PolyaExp(poly P){return PolyaExp(P,P.size());}
        voi println(poly P,uint n)
        {
            for(uint i=0;i<n;i++){
                if(i)putchar(' ');
                P.val(i).print();
            }
            putchar('\n');
        }
        voi println(poly P){println(P,P.size());}
};
template<const ullt p=998244353>
class FWT_Mod
{
	public:
		typedef mod_ullt<p>modint;
        typedef std::vector<modint>modvec;
	private:
		uint n;
	public:
		FWT_Mod():n(0){}
		voi bzr(uint len){n=1;while(n<len)n<<=1;}
		uint size(){return n;}
		voi OR(modvec&x,bol op)
		{
			if(x.size()<n)x.resize(n);
			for(uint i=1;i<n;i<<=1)for(uint j=0;j<n;j+=i<<1)for(uint k=0;k<i;k++)
				op?x[i+j+k]-=x[j+k]:x[i+j+k]+=x[j+k];
		}
		voi AND(modvec&x,bol op)
		{
			if(x.size()<n)x.resize(n);
			for(uint i=1;i<n;i<<=1)for(uint j=0;j<n;j+=i<<1)for(uint k=0;k<i;k++)
				op?x[j+k]-=x[i+j+k]:x[j+k]+=x[i+j+k];
		}
		voi XOR(modvec&x,bol op)
		{
			if(x.size()<n)x.resize(n);
			for(uint i=1;i<n;i<<=1)for(uint j=0;j<n;j+=i<<1)for(uint k=0;k<i;k++)
			{
				modint u=x[j+k],t=x[i+j+k];x[j+k]=u+t,x[i+j+k]=u-t;
			}
			if(op){modint v=modint(n).inv();for(uint i=0;i<n;i++)x[i]*=v;}
		}
};
const ullt Mod=998244353,g=3;
typedef mod_ullt<Mod>modint;
typedef std::vector<modint>modvec;
typedef poly_NTT<Mod,g>poly;
typedef poly_eval<Mod,g>eval;
typedef poly_inter<Mod,g>inter;
typedef poly_cpd<Mod,g>cpd;
typedef FWT_Mod<Mod>FWT;
modint P[30005],Q[30005];
poly Y;
// 下降幂多项式
int main()
{
    P[0]=1;for(uint i=1;i<=30000;i++)P[i]=P[i-1]*i;
    Q[30000]=P[30000].inv();for(uint i=30000;i;i--)Q[i-1]=Q[i]*i;
    uint n,m;modint x;scanf("%u%u",&n,&m),x.read();
    Y.chg_deg(m);
    for(uint i=0;i<=m;i++)Y[i].read(),Y[i]*=Q[i];
    poly User(m+1);
    for(uint i=0;i<=m;i++)User[i]=(i&1?Mod-1:1)*Q[i];
    Y*=User,Y.chg_deg(m);
    modint v(1),ans;
    for(uint i=0;i<=n&&i<=m;i++)ans+=v*Y[i],v*=x*(n-i);
    ans.println();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 5
Accepted
time: 1ms
memory: 3492kb

input:

100 100 133860013
794216030 545630468 535373340 681004830 753155468 2680450 105693375 518005489 897014100 500942829 997151601 667007464 91736015 433225102 925017061 85974855 500030009 363988940 173653425 968669105 289184566 517436890 756486993 235255223 69278880 107265295 446355639 892379811 1361846...

output:

865916449

result:

ok 1 number(s): "865916449"

Test #2:

score: 5
Accepted
time: 0ms
memory: 3348kb

input:

1000 1000 379317338
460923986 466041450 290967353 501524928 718239371 450092437 427711243 677445812 696620161 681064347 812763849 419590567 546691054 492234099 219271744 511342569 97760050 207346856 604091175 555559126 624742734 206429806 443776004 376878852 784982516 83274156 562982864 639453584 46...

output:

569471924

result:

ok 1 number(s): "569471924"

Test #3:

score: 5
Accepted
time: 1ms
memory: 3404kb

input:

10000 90 553134058
795889349 258493606 94911677 152744143 885766671 69487209 29458125 599019659 63525831 810219747 235128336 574741720 292250567 979032093 825318040 535403322 653684191 418165265 441554942 118132526 965057080 393835787 667654424 117852644 53523894 595342039 255107077 354301570 945160...

output:

340512707

result:

ok 1 number(s): "340512707"

Test #4:

score: 5
Accepted
time: 1ms
memory: 3416kb

input:

90909 95 76191496
796190005 336013330 313281818 136122228 910767049 188622961 231812373 491964897 464583289 619007453 312511038 200466464 978838700 824986489 540609888 778760819 762248930 627440917 134081709 760402976 366755668 158413671 417643922 104148038 830279350 51055965 274012172 658446902 719...

output:

829201124

result:

ok 1 number(s): "829201124"

Test #5:

score: 5
Accepted
time: 0ms
memory: 3380kb

input:

909090 97 37348550
576471799 465023447 458616093 80158438 44424278 977371148 668982991 543389921 810652672 170851218 142499489 234484449 683697511 485750136 673161788 325731944 494775339 532998562 479502525 896103030 809765952 716790561 187573762 627968446 151694545 407166464 42314681 714665873 9795...

output:

407880684

result:

ok 1 number(s): "407880684"

Test #6:

score: 5
Accepted
time: 1ms
memory: 3416kb

input:

999999787 1 1
962552531 143301326

output:

234791071

result:

ok 1 number(s): "234791071"

Test #7:

score: 5
Accepted
time: 0ms
memory: 3596kb

input:

999999944 2 773504401
0 1 4

output:

278084784

result:

ok 1 number(s): "278084784"

Test #8:

score: 5
Accepted
time: 1ms
memory: 3588kb

input:

999999135 2 465747000
0 0 2

output:

180751969

result:

ok 1 number(s): "180751969"

Test #9:

score: 5
Accepted
time: 1ms
memory: 3472kb

input:

1000000000 3 21216356
111247080 796755814 583439797 842526695

output:

406964762

result:

ok 1 number(s): "406964762"

Test #10:

score: 5
Accepted
time: 1ms
memory: 3424kb

input:

993999563 6 665637445
922376106 627256748 953905014 681550999 548948411 265575769 328660250

output:

682043189

result:

ok 1 number(s): "682043189"

Test #11:

score: 5
Accepted
time: 1ms
memory: 3540kb

input:

994999897 9 922816200
828957950 382766786 455589991 210276899 220065322 664274186 428648517 257488462 865910676 251386572

output:

673739493

result:

ok 1 number(s): "673739493"

Test #12:

score: 5
Accepted
time: 0ms
memory: 3540kb

input:

908115435 33 799549151
453603176 62646701 890881822 396931885 70416206 673207832 857754112 802010882 460326250 560139719 98491302 835079926 472749530 57037949 229925163 38474573 21507548 137798115 474868202 792830110 643994954 239044587 734781970 121637498 298208316 92180032 975930165 538485175 7107...

output:

905808768

result:

ok 1 number(s): "905808768"

Test #13:

score: 5
Accepted
time: 1ms
memory: 3420kb

input:

989936365 66 412064955
595980804 271574715 412074517 58062701 831714434 359570877 742147685 155224669 265613885 972072848 42704300 136126491 111626610 517572502 928956602 604626622 756617089 665494219 726264120 903830463 606679310 703949933 293076343 168209203 180950660 474206788 183342273 869837383...

output:

230850567

result:

ok 1 number(s): "230850567"

Test #14:

score: 5
Accepted
time: 2ms
memory: 3544kb

input:

970601872 99 390252088
572320165 607178150 46924041 19471981 112981292 474320918 982440653 245751152 508100063 554542767 45770878 118904034 32230991 452469915 282662996 801239911 876383213 778367560 895216325 334399489 994670213 236933205 236828053 541634589 420615707 7994207 829579559 506082179 266...

output:

965811382

result:

ok 1 number(s): "965811382"

Test #15:

score: 5
Accepted
time: 2ms
memory: 3604kb

input:

917655104 1000 163840370
352803054 832726299 260369539 674429993 435887494 355313012 386218137 702110 447298521 232388868 859813990 381756986 449875391 951572596 398333110 159059177 132977194 479357043 168012289 578138993 393431252 260985856 436532189 818326240 873134815 24586604 95320269 162471606 ...

output:

57254422

result:

ok 1 number(s): "57254422"

Test #16:

score: 5
Accepted
time: 2ms
memory: 3540kb

input:

975664260 2000 245386427
977847748 787405635 132906317 188218658 105185168 546915055 903559565 535054072 66735269 14145011 265944620 95295369 6870729 384079925 484479806 326422815 208099523 885109185 200681946 653739240 253494620 512397440 732917130 459625672 348645863 31129514 397328802 904655340 4...

output:

469000978

result:

ok 1 number(s): "469000978"

Test #17:

score: 5
Accepted
time: 2ms
memory: 3716kb

input:

920546466 4000 947740772
666495508 334163627 268420669 740051791 379160751 645274460 64979784 581413242 967035695 18056222 209272995 164751974 564590654 332491059 665770280 623844038 533456666 966426211 103393463 61570520 163962785 376646945 434544899 811168427 314454434 889367016 623941355 56521790...

output:

875136086

result:

ok 1 number(s): "875136086"

Test #18:

score: 5
Accepted
time: 3ms
memory: 3788kb

input:

985661745 8000 471619683
940831080 428991947 403368000 52357964 478374085 927701580 169923691 334930807 970221025 591659100 258099967 715619468 502586108 83803715 830966705 440086938 125330363 761191120 556779903 484653833 126638033 26475019 461211776 919913639 773405080 471222411 441429297 70016502...

output:

41366997

result:

ok 1 number(s): "41366997"

Test #19:

score: 5
Accepted
time: 2ms
memory: 4212kb

input:

942855705 12000 620856510
870226084 744842350 733038341 71326354 324783711 946249089 47913889 552377847 956182823 909173925 496221724 748662643 869918222 15097898 324783182 940101151 351130713 885540354 956927798 65392299 702092339 696611786 157660746 150535554 259370269 526688412 342932504 91808938...

output:

565201163

result:

ok 1 number(s): "565201163"

Test #20:

score: 5
Accepted
time: 8ms
memory: 4916kb

input:

962657420 20000 707529234
473540237 731236314 764037756 189576043 863113652 705762029 638342941 99272398 57159476 462183032 99431513 476596471 42953200 381023313 442265077 366510437 178310211 415208780 736316039 673552574 438809737 310201283 938886298 331712259 698862232 12012042 121584953 987945580...

output:

652536354

result:

ok 1 number(s): "652536354"

Extra Test:

score: 0
Extra Test Passed