/* Things to notice: 1. do not calculate useless values 2. do not use similar names Things to check: 1. submit the correct file 2. time (it is log^2 or log) 3. memory 4. prove your naive thoughts 5. long long 6. corner case like n=0,1,inf or n=m 7. check if there is a mistake in the ds or other tools you use 8. fileio in some oi-contest 9. module on time 10. the number of a same divisor in a math problem 11. multi-information and queries for dp and ds problems */ #include using namespace std; #define int long long #define fi first #define se second #define pii pair #define mp make_pair #define pb push_back const int mod=998244353; const int inf=0x3f3f3f3f; const int INF=1e18; int fpow(int x,int b) { if(x==0) return 0; if(b==0) return 1; int res=1; while(b>0) { if(b&1) res=1LL*res*x%mod; x=1LL*x*x%mod; b>>=1; } return res; } struct Mypoly { int n,m; int a[2200005],b[2200005],p[2200005],c[2200005]; int N=1,lg; // ntt void ntt(int *A) { for(int i=0;i>1]>>1)|((i&1)<<(lg-1)); } // poly mul vector mul(vector P,vector Q) { // memset(a,0,sizeof(a)),memset(b,0,sizeof(b)),memset(p,0,sizeof(p)); n=P.size()-1,m=Q.size()-1; for(int i=0;i<=n;i++) a[i]=P[i]; for(int i=0;i<=m;i++) b[i]=Q[i]; init_butterfly(n+m+1); ntt(a),ntt(b); for(int i=0;i res; res.clear(); for(int i=0;i<=n+m;i++) res.pb(a[i]); for(int i=0;i<=2*N;i++) a[i]=b[i]=p[i]=0; return res; } // poly inv void work_getinv(int deg) { if(deg==1) { b[0]=fpow(a[0],mod-2); return; } work_getinv((deg+1)>>1); init_butterfly(deg<<1); for(int i=0;i getinv(vector P) { n=P.size(); // memset(a,0,sizeof(a)),memset(b,0,sizeof(b)),memset(p,0,sizeof(p)); for(int i=0;i Q; for(int i=0;ix) return 0; if(x==y||y==0) return 1; return 1LL*fac[x]*ifac[x-y]%mod*ifac[y]%mod; } void init(int x) { fac[0]=fac[1]=1; for(int i=2;i<=x;i++) fac[i]=1LL*fac[i-1]*i%mod; ifac[x]=fpow(fac[x],mod-2); // x should be less than mod!!! for(int i=x-1;i>=0;i--) ifac[i]=1LL*ifac[i+1]*(i+1)%mod; } int n; int a[100005],dp[100005]; void divide(int l,int r) { if(l==r) { dp[l]=(dp[l]+ifac[l])%mod; dp[l]=dp[l]*(fpow(2,a[l])-1)%mod; // cout<>1; divide(l,mid); vector P,Q; for(int i=0;i<=r-l+1;i++) P.pb(ifac[i]); for(int i=l;i<=mid;i++) Q.pb(dp[i]); P=poly.mul(P,Q); for(int i=mid+1;i<=r;i++) dp[i]=(dp[i]+P[i-l])%mod; divide(mid+1,r); } void solve() { cin>>n; init(300000); while(n--) { int x; cin>>x; a[x]++; } int ans=0; divide(1,100000); for(int i=1;i<=100000;i++) ans=(ans+dp[i]*fac[i])%mod; cout<>_; while(_--) solve(); return 0; }