1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
| #include <cstdio> #include <iostream> #include <cstring> #include <algorithm> #include <vector> #define PB push_back #define MP make_pair #define PII pair<int,int> #define FIR first #define SEC second #define ll long long using namespace std; template <class T> inline void rd(T &x) { x=0; char c=getchar(); int f=1; while(!isdigit(c)) { if(c=='-') f=-1; c=getchar(); } while(isdigit(c)) x=x*10-'0'+c,c=getchar(); x*=f; } const int mod=998244353; const int N=2e5+10; ll Pow(ll x,int y) { ll res=1; for(;y;y>>=1,x=x*x%mod) if(y&1) res=res*x%mod; return res; }
namespace Poly { const int N=(1<<18)+10; int wn[2][N],rev[N]; void getwn(int l) { for(int i=1;i<(1<<l);i<<=1) { int w0=Pow(3,(mod-1)/(i<<1)),w1=Pow(3,mod-1-(mod-1)/(i<<1)); wn[0][i]=wn[1][i]=1; for(int j=1;j<i;++j) wn[0][i+j]=wn[0][i+j-1]*(ll)w0%mod, wn[1][i+j]=wn[1][i+j-1]*(ll)w1%mod; } } void getr(int len) { for(int i=1;i<len;++i) rev[i]=(rev[i>>1]>>1)|((i&1)*(len>>1)); } void FFT(int *A,int len,int f) { for(int i=0;i<len;++i) if(rev[i]<i) swap(A[i],A[rev[i]]); for(int l=1;l<len;l<<=1) for(int i=0;i<len;i+=l<<1) for(int j=0;j<l;++j) { int t0=A[i+j],t1=A[i+l+j]*(ll)wn[f][l+j]%mod; A[i+j]=(t0+t1)%mod,A[i+l+j]=(t0-t1)%mod; } if(f==1) { int Inv=Pow(len,mod-2); for(int i=0;i<len;++i) A[i]=A[i]*(ll)Inv%mod; } } void Mul(int *A,int *B,int *C,int n,int m,int l3) { static int a[N],b[N]; int len=1; while(len<n+m-1||len<l3) len<<=1; getr(len); for(int i=0;i<len;++i) a[i]=b[i]=0; for(int i=0;i<n;++i) a[i]=A[i]; for(int i=0;i<m;++i) b[i]=B[i]; FFT(a,len,0),FFT(b,len,0); for(int i=0;i<len;++i) a[i]=a[i]*(ll)b[i]%mod; FFT(a,len,1); for(int i=0;i<l3;++i) C[i]=a[i]; } void Mul(int *A,int *B,int *C,int n,int m) { Mul(A,B,C,n,m,n+m-1); } inline void Mul(vector<int> &A,vector<int> &B,vector<int> &C) { static int a[N],b[N]; int len=1; while(len<A.size()+B.size()-1) len<<=1; getr(len); for(int i=0;i<len;++i) a[i]=b[i]=0; for(int i=0;i<A.size();++i) a[i]=A[i]; for(int i=0;i<B.size();++i) b[i]=B[i]; FFT(a,len,0),FFT(b,len,0); for(int i=0;i<len;++i) a[i]=a[i]*(ll)b[i]%mod; FFT(a,len,1); C.resize(A.size()+B.size()-1); for(int i=0;i<C.size();++i) C[i]=a[i]; } }
vector<int> g[N],s[N<<2]; inline void solve(int l,int r,int c) { if(l==r) return (void)(s[c]=g[l]); int mid=l+r>>1; solve(l,mid,c<<1),solve(mid+1,r,c<<1|1); Poly::Mul(s[c<<1],s[c<<1|1],s[c]); s[c<<1].clear(); s[c<<1|1].clear(); } ll fac[N<<1],inv[N<<1];
int A[N],B[N],C[N]; ll f[N];
inline void getfac(int n) { fac[0]=1; for(int i=1;i<=n;++i) fac[i]=fac[i-1]*i%mod; inv[n]=Pow(fac[n],mod-2); for(int i=n;i>=1;--i) inv[i-1]=inv[i]*i%mod; } inline ll binom(int n,int m) { return fac[n]*inv[m]%mod*inv[n-m]%mod; } int ra[N]; int main() { int m; rd(m); getfac(400000); Poly::getwn(18);
int coe=0; for(int now=1,a;now<=m;++now) { rd(a),coe+=a; for(int i=0;i<=a;++i) A[i]=B[i]=0; if(now==1) { for(int i=1;i<=a;++i) A[i]=binom(a+i-1,2*i-1)*fac[i-1]%mod*(i&1?1:-1); for(int i=1;i<=a;++i) B[a-i]=inv[i-1]; Poly::Mul(A,B,C,a+1,a+1); for(int i=0;i<a;++i) f[i]=C[i+a]*inv[i]%mod*inv[i+1]%mod*(i&1?-1:1);
} else { for(int i=1;i<=a;++i) A[i]=binom(a+i-1,2*i-1)*fac[i-1]%mod*(i&1?-1:1); for(int i=0;i<a;++i) B[a-i]=inv[i]; Poly::Mul(A,B,C,a+1,a+1); for(int i=1;i<=a;++i) f[i]=C[i+a]*inv[i]%mod*inv[i-1]%mod*(i&1?-1:1);
} for(int i=0;i<=a;++i) g[now].PB(f[i]),f[i]=0;
} solve(1,m,1); int ans=0;
for(int i=0;i<s[1].size();++i) (ans+=s[1][i]*fac[i]%mod)%=mod; ans=1ll*ans*coe%mod; printf("%d",(ans+mod)%mod); return 0; }
|