#include #pragma GCC target("avx") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") using namespace std; #define lli long long int #define uli unsigned long long int #define INF 9999999999 #define rep(i,m,n) for(lli i = m;i < n;i++) #define rrep(i,m,n) for(lli i=m-1;i>=n;i--) #define pb(n) push_back(n) #define UE(N) N.erase(unique(N.begin(),N.end()),N.end()); #define Sort(n) sort(n.begin(), n.end()) #define Rev(n) reverse(n.begin(),n.end()) #define Out(S) cout << S << endl #define NeOut(S) cout << S #define HpOut(S) cout << setprecision(25) << S << endl #define Vec(K,L,N,S) vector K(N,S) #define DV(K,L,N,M,S) vector> K(N,vector(M,S)) #define TV(K,L,N,M,R,S) vector>> K(N,vector>(M,vector(R,S))) #define pint pair #define paf(L,R) pair //#define mod 1000000007 #define MAX 10000000 #define ALL(a) a.begin(),a.end() #define chmax(a, b) a = (((a)<(b)) ? (b) : (a)) #define chmin(a, b) a = (((a)>(b)) ? (b) : (a)) lli A,B,C,D,E,F,N,M,K,L,X,Y,Z,H,W,sum=0,num=0,flag=0;string S,T; Vec(P,lli,200000,0); lli modpow(lli n,lli k,lli m){ if(k==0)return 1; else if(k%2==1)return modpow(n,k-1,m)*n%m; else{ lli temp=modpow(n,k/2,m); return temp*temp%m; } } long long modinv(long long a, long long mod) { long long b = mod, u = 1, v = 0; while (b) { long long t = a/b; a -= t*b; swap(a, b); u -= t*v; swap(u, v); } u %= mod; if (u < 0) u += mod; return u; } const int MOD = 998244353; // to be set appropriately const long long PR = 3; // to be set appropriately void trans(vector &v, bool inv = false) { int n = (int)v.size(); for (int i = 0, j = 1; j < n-1; j++) { for (int k = n>>1; k > (i ^= k); k >>= 1); if (i > j) swap(v[i], v[j]); } for (int t = 2; t <= n; t <<= 1) { long long bw = modpow(PR, (MOD-1)/t, MOD); if (inv) bw = modinv(bw, MOD); for (int i = 0; i < n; i += t) { long long w = 1; for (int j = 0; j < t/2; ++j) { int j1 = i + j, j2 = i + j + t/2; long long c1 = v[j1], c2 = v[j2] * w % MOD; v[j1] = c1 + c2; v[j2] = c1 - c2 + MOD; while (v[j1] >= MOD) v[j1] -= MOD; while (v[j2] >= MOD) v[j2] -= MOD; w = w * bw % MOD; } } } if (inv) { long long inv_n = modinv(n, MOD); for (int i = 0; i < n; ++i) v[i] = v[i] * inv_n % MOD; } } vector NTT(vector A, vector B) { int size_a = 1; while (size_a < A.size()) size_a <<= 1; int size_b = 1; while (size_b < B.size()) size_b <<= 1; int size_fft = max(size_a, size_b) << 1; vector cA(size_fft, 0), cB(size_fft, 0), cC(size_fft, 0); for (int i = 0; i < A.size(); ++i) cA[i] = A[i]; for (int i = 0; i < B.size(); ++i) cB[i] = B[i]; trans(cA); trans(cB); for (int i = 0; i < size_fft; ++i) cC[i] = cA[i] * cB[i] % MOD; trans(cC, true); vector res((int)A.size() + (int)B.size() - 1); for (int i = 0; i < res.size(); ++i) res[i] = cC[i]; return res; } vector divide_and_solve(int left,int right){//f_l(x)からf_r(x)までの積 if(right-left==1){ Vec(v,lli,2,1); v[1]=P[left]; return v; } auto vl=divide_and_solve(left,(left+right)/2); auto vr=divide_and_solve((left+right)/2,right); int ls=vl.size(),rs=vr.size(); if(ls+rs<1000){ Vec(marge,lli,ls+rs-1,0); rep(i,0,ls)rep(j,0,rs){ marge[i+j]+=(vl[i]*vr[j])%MOD; marge[i+j]%=MOD; } return marge; } else return NTT(vl,vr); } int main(){ ios::sync_with_stdio(false); cin.tie(0); cin >> N >> M; Vec(Q,lli,M,0); P.resize(N); rep(i,0,N){ cin >> P[i]; P[i]--; P[i]%=MOD; } rep(i,0,M)cin >> Q[i]; auto ans=divide_and_solve(0,N); Rev(ans); rep(i,0,M)Out(ans[Q[i]]%MOD); }