#include #include #include #include #include #include #include using namespace std; typedef long long ll; const ll MOD = 998244353; int N, Q; ll A[200000], B[10000]; #define root 3 unsigned int add(const unsigned int x, const unsigned int y) { return (x + y < MOD) ? x + y : x + y - MOD; } unsigned int sub(const unsigned int x, const unsigned int y) { return (x >= y) ? (x - y) : (MOD - y + x); } unsigned int mul(const unsigned int x, const unsigned int y) { return (unsigned long long)x * y % MOD; } unsigned int mod_pow(unsigned int x, unsigned int n) { unsigned int res = 1; while(n > 0){ if(n & 1){ res = mul(res, x); } x = mul(x, x); n >>= 1; } return res; } unsigned int inverse(const unsigned int x) { return mod_pow(x, MOD - 2); } void ntt(vector& a, const bool rev = false) { unsigned int i, j, k, l, p, q, r, s; const unsigned int size = a.size(); if(size == 1) return; vector b(size); r = rev ? (MOD - 1 - (MOD - 1) / size) : (MOD - 1) / size; s = mod_pow(root, r); vector kp(size / 2 + 1, 1); for(i = 0; i < size / 2; ++i) kp[i + 1] = mul(kp[i], s); for(i = 1, l = size / 2; i < size; i <<= 1, l >>= 1){ for(j = 0, r = 0; j < l; ++j, r += i){ for(k = 0, s = kp[i * j]; k < i; ++k){ p = a[k + r], q = a[k + r + size / 2]; b[k + 2 * r] = add(p, q); b[k + 2 * r + i] = mul(sub(p, q), s); } } swap(a, b); } if(rev){ s = inverse(size); for(i = 0; i < size; i++){ a[i] = mul(a[i], s); } } } vector convolute(const vector& a, const vector& b) { const int size = (int)a.size() + (int)b.size() - 1; int t = 1; while(t < size){ t <<= 1; } vector A(t, 0), B(t, 0); for(int i = 0; i < (int)a.size(); i++){ A[i] = a[i]; } for(int i = 0; i < (int)b.size(); i++){ B[i] = b[i]; } ntt(A), ntt(B); for (int i = 0; i < t; i++){ A[i] = mul(A[i], B[i]); } ntt(A, true); A.resize(size); return A; } vector calc(int l, int r){ if(l == r){ vector ans; ans.push_back(A[l]-1); ans.push_back(1); return ans; } int c = (l+r)/2; auto vl = calc(l, c); auto vr = calc(c+1, r); auto ans = convolute(vl, vr); return ans; } int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(10) << fixed; cin >> N >> Q; for(int i = 0; i < N; i++) { cin >> A[i]; A[i]%= MOD; } for(int i = 0; i < Q; i++) cin >> B[i]; auto conv = calc(0, N-1); for(int i = 0; i < Q; i++) { cout << conv[B[i]] << endl; } }