#include using namespace std; #define DEBUG(x) cerr<<#x<<": "< #define vl vector #define vii vector< vector > #define vll vector< vector > #define vs vector #define pii pair #define pis pair #define psi pair #define pll pair template pair operator+(const pair &s, const pair &t) { return pair(s.first + t.first, s.second + t.second); } template pair operator-(const pair &s, const pair &t) { return pair(s.first - t.first, s.second - t.second); } template ostream& operator<<(ostream& os, pair p) { os << "(" << p.first << ", " << p.second << ")"; return os; } #define X first #define Y second #define rep(i,n) for(int i=0;i<(int)(n);i++) #define rep1(i,n) for(int i=1;i<=(int)(n);i++) #define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--) #define rrep1(i,n) for(int i=(int)(n);i>0;i--) #define REP(i,a,b) for(int i=a;i bool chmax(T &a, const T &b) { if (a bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; } #define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end()); const ll inf = 1000000001; const ll INF = (ll)1e18 + 1; const long double pi = 3.1415926535897932384626433832795028841971L; #define Sp(p) cout<で宣言 // グローバルで一度宣言すれば何度でも使用可能 // https://atcoder.jp/contests/jsc2019-final/submissions/7782824 template< int mod, int primitiveroot > struct NTT { vector< vector< int > > rts, rrts; void ensure_base(int N) { if(rts.size() >= N) return; rts.resize(N), rrts.resize(N); for(int i = 1; i < N; i <<= 1) { if(rts[i].size()) continue; int w = mod_pow(primitiveroot, (mod - 1) / (i * 2)); int rw = inverse(w); rts[i].resize(i), rrts[i].resize(i); rts[i][0] = 1, rrts[i][0] = 1; for(int k = 1; k < i; k++) { rts[i][k] = mul(rts[i][k - 1], w); rrts[i][k] = mul(rrts[i][k - 1], rw); } } } inline int mod_pow(int x, int n) { int ret = 1; while(n > 0) { if(n & 1) ret = mul(ret, x); x = mul(x, x); n >>= 1; } return ret; } inline int inverse(int x) { return mod_pow(x, mod - 2); } inline int add(int x, int y) { x += y; if(x >= mod) x -= mod; return x; } inline int mul(int a, int b) { return int(1LL * a * b % mod); } void DiscreteFourierTransform(vector< int > &F, bool rev) { const int N = (int) F.size(); ensure_base(N); for(int i = 0, j = 1; j + 1 < N; j++) { for(int k = N >> 1; k > (i ^= k); k >>= 1); if(i > j) swap(F[i], F[j]); } for(int i = 1; i < N; i <<= 1) { for(int j = 0; j < N; j += i * 2) { for(int k = 0; k < i; k++) { int s = F[j + k], t = mul(F[j + k + i], rev ? rrts[i][k] : rts[i][k]); F[j + k] = add(s, t), F[j + k + i] = add(s, mod - t); } } } if(rev) { int temp = inverse(N); for(int i = 0; i < N; i++) F[i] = mul(F[i], temp); } } vector< int > Multiply(const vector< int > &A, const vector< int > &B) { int sz = 1; while(sz < A.size() + B.size() - 1) sz <<= 1; vector< int > F(sz), G(sz); for(int i = 0; i < A.size(); i++) F[i] = A[i]; for(int i = 0; i < B.size(); i++) G[i] = B[i]; DiscreteFourierTransform(F, false); DiscreteFourierTransform(G, false); for(int i = 0; i < sz; i++) F[i] = mul(F[i], G[i]); DiscreteFourierTransform(F, true); F.resize(A.size() + B.size() - 1); return F; } }; NTT<998244353, 3> ntt; vl calc(vl& a, int l, int r) { if (l + 1 == r) { vl res = {a[l] - 1, 1}; return res; } int m = (l + r) / 2; vl b1 = calc(a, l, m), b2 = calc(a, m, r); vl res = ntt.Multiply(b1, b2); return res; } signed main() { int n, q; cin >> n >> q; vl a(n); rep (i, n) { cin >> a[i]; a[i] %= MOD; } auto res = calc(a, 0, n); while (q--) { int x; cin >> x; cout << res[x] << endl; } }