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 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
| #include <bits/stdc++.h> using namespace std; #define FO(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout) #define fo(i,j,k) for(int i=(j),end_i=(k);i<=end_i;i++) #define ff(i,j,k) for(int i=(j),end_i=(k);i< end_i;i++) #define fd(i,j,k) for(int i=(j),end_i=(k);i>=end_i;i--) #define DEBUG(x) cerr<<#x<<"="<<x<<endl #define all(x) (x).begin(),(x).end() #define cle(x) memset(x,0,sizeof(x)) #define lowbit(x) ((x)&-(x)) #define ll long long #define ull unsigned ll #define db double #define lb long db #define pb push_back #define mp make_pair #define fi first #define se second inline int read() { int x=0; char ch=getchar(); bool f=0; for(;ch<'0'||ch>'9';ch=getchar()) if(ch=='-') f=1; for(;ch>='0'&&ch<='9';ch=getchar()) x=(x<<3)+(x<<1)+(ch^48); return f?-x:x; } #define CASET fo(___,1,read())
const ll mod=998244353; inline ll Add(ll x,ll y){x+=y; return (x<mod)?x:x-mod;} inline ll Dec(ll x,ll y){x-=y; return (x<0)?x+mod:x;} inline ll Mul(ll x,ll y){return x*y%mod;} inline ll Pow(ll x,ll y) { y%=(mod-1);ll ans=1;for(;y;y>>=1,x=x*x%mod)if(y&1) ans=ans*x%mod; return ans; } const ll mo=998244352;
db pi=acos(-1.); struct P{ db x,y; P(db _x=0,db _y=0) {x=_x,y=_y;} friend inline P operator +(const P&A,const P&B) { return (P){A.x+B.x,A.y+B.y}; } friend inline P operator -(const P&A,const P&B) { return (P){A.x-B.x,A.y-B.y}; } friend inline P operator *(const P&A,const P&B) { return (P){A.x*B.x-A.y*B.y,A.x*B.y+A.y*B.x}; } friend inline P operator /(const P&A,const db &x) { return (P){A.x/x,A.y/x}; } }; P conj(P A) {return (P){A.x,-A.y};}
const int M=1<<20; P W[M]; int R[M]; inline void PolyInit() { for(int i=1;i<M;i<<=1) fo(j,0,i-1) W[i+j]=(P){cos(pi*j/i),sin(pi*j/i)}; } typedef vector<P> Poly; inline void ntt(P *a,int n,int t) { fo(i,0,n-1) { R[i]=(R[i>>1]>>1)|((i&1)*(n>>1)); if(i<R[i]) swap(a[i],a[R[i]]); } P w; for(int i=1;i<n;i<<=1) for(int j=0;j<n;j+=(i<<1)) for(int k=0;k<i;k++) w=W[i+k]*a[i+j+k], a[i+j+k]=a[j+k]-w, a[j+k]=a[j+k]+w; if(t==1) return; reverse(a+1,a+n); fo(i,0,n-1) a[i]=a[i]/n; } inline void ntt(Poly &A,int n,int t){ntt(&A[0],n,t);} inline Poly operator +(Poly A,Poly B) { A.resize(max(A.size(),B.size())); fo(i,0,B.size()-1) A[i]=A[i]+B[i]; return A; } #define Real(A) ((ll)floor(A.x+0.5)) #define Imag(A) ((ll)floor(A.y+0.5)) inline Poly operator *(Poly A,Poly B) { static Poly C,D; int n=A.size(),m=B.size(),k=n+m-1,len=1; for(;len<k;len<<=1); C.resize(len); D.resize(len); A.resize(len); B.resize(len); ff(i,0,len) C[i]=(P){Real(A[i])&32767,Real(A[i])>>15},D[i]=(P){Real(B[i])&32767,Real(B[i])>>15}; ntt(C,len,1); ntt(D,len,1); int j; ff(i,0,len) { P d4,d0,d1,d2,d3; j=(len-i)&(len-1); d4=conj(C[j]); d0=(d4+C[i])*P(0.5,0); d1=(d4-C[i])*P(0,0.5); d4=conj(D[j]); d2=(d4+D[i])*P(0.5,0); d3=(d4-D[i])*P(0,0.5); A[i]=d0*d2+d1*d3*P(0,1); B[i]=d0*d3+d1*d2; } ntt(A,len,-1); ntt(B,len,-1); ff(i,0,len) C[i]=(Real(A[i]) + (Imag(A[i]) % mo << 30) + (Real(B[i]) % mo << 15))%mo; C.resize(k); return C; }
const int N=100010;
Poly A; int n,sum; int a[N];
Poly solve(int l,int r) { if(l==r) { Poly B; B.resize(a[l]+1); fo(i,0,a[l]) B[i]=0; B[0]=1; B[a[l]]=1; return B; } int mid=(l+r)>>1; return solve(l,mid)*solve(mid+1,r); }
int main() { PolyInit(); CASET { n=read(); sum=0; fo(i,1,n) sum+=(a[i]=read()); bool flag=0; fo(i,1,n) if(a[i]==0) {flag=1; break;} if(flag){puts("0"); continue;} A=solve(1,n); ll ans=1; fo(i,1,sum) ans=ans*Pow(i,Real(A[i]))%mod; printf("%lld\n",ans); } return 0; }
|