#include #pragma GCC target("avx") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") using namespace std; #define rep(i,m,n) for(long long i = m; i < n; i++) #define Rev(n) reverse(n.begin(),n.end()) #define Vec(K,L,N,S) vector K(N,S) #define mod 998244353 long long modpow(long long n, long long k, long long m) { if(!k) return 1; else if(k & 1) return modpow(n, k - 1, m) * n % m; else { long long temp = modpow(n, k / 2, m); return temp * temp % m; } } long long modinv(long long a, long long m) { long long b = m, u = 1, v = 0; while (b) { long long t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= m; if (u < 0) u += m; return u; } //from: yosupot(https://github.com/yosupo06/Algorithm/blob/master/src/math/nft.hpp) void nft(bool type, vector& a) { int n = int(a.size()), s = 0; while ((1 << s) < n) s++; assert(1 << s == n); static vector ep, iep; while (int(ep.size()) <= s) { ep.push_back(modpow(3, (mod - 1) / (1 << ep.size()), mod)); iep.push_back(modinv(ep.back(), mod)); } vector b(n); for (int i = 1; i <= s; i++) { int w = 1 << (s - i); long long base = type ? iep[i] : ep[i], now = 1; for (int y = 0; y < n / 2; y += w) { for (int x = 0; x < w; x++) { auto l = a[y << 1 | x]; auto r = now * a[y << 1 | x | w] % mod; b[y | x] = (l + r) % mod; b[y | x | n >> 1] = (l - r + mod) % mod; } now = now * base % mod; } swap(a, b); } } vector multiply_nft(const vector& a, const vector& b) { int n = a.size(), m = b.size(); if (!n || !m) return {}; if (min(n, m) <= 32) { vector ans(n + m - 1); for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) ans[i + j] = (ans[i + j] + a[i] * b[j] % mod) % mod; return ans; } int lg = 0; while ((1 << lg) < n + m - 1) lg++; int z = 1 << lg; auto a2 = a, b2 = b; a2.resize(z); b2.resize(z); nft(false, a2); nft(false, b2); for (int i = 0; i < z; i++) a2[i] = a2[i] * b2[i] % mod; nft(true, a2); a2.resize(n + m - 1); long long iz = modinv(z, mod); for (int i = 0; i < n + m - 1; i++) a2[i] = a2[i] * iz % mod; return a2; } // Cooley-Tukey: input -> butterfly -> bit reversing -> output から // bit reversingを抜いたもの 直接使うな void butterfly(bool type, vector& a) { int n = a.size(), h = 0; while ((1 << h) < n) h++; assert(1 << h == n); if (n == 1) return; static vector snow, sinow; if (snow.empty()) { long long sep = 1, siep = 1; long long Mod = mod - 1; long long di = 4; while (Mod % di == 0) { long long ep = modpow(3, Mod / di, mod); long long iep = modinv(ep, mod); snow.push_back(siep * ep % mod); sinow.push_back(sep * iep % mod); sep = sep * ep % mod; siep = siep * iep % mod; di = di * 2 % mod; } } if (!type) { // fft for (int ph = 1; ph <= h; ph++) { // phase ph: size w -> 2w の FFT, p 並列 int w = 1 << (ph - 1), p = 1 << (h - ph); long long now = 1; for (int s = 0; s < w; s++) { int offset = s << (h - ph + 1); for (int i = 0; i < p; i++) { auto l = a[i + offset]; auto r = a[i + offset + p] * now % mod; a[i + offset] = (l + r) % mod; a[i + offset + p] = (l - r + mod) % mod; } int u = __builtin_ctzll(~s); now = now * snow[u] % mod; } } } else { // ifft for (int ph = h; ph >= 1; ph--) { int w = 1 << (ph - 1), p = 1 << (h - ph); long long inow = 1; for (int s = 0; s < w; s++) { int offset = s << (h - ph + 1); for (int i = 0; i < p; i++) { auto l = a[i + offset]; auto r = a[i + offset + p]; a[i + offset] = (l + r) % mod; a[i + offset + p] = (l - r + mod) * inow % mod; } int u = __builtin_ctzll(~s); inow = inow * sinow[u] % mod; } } } } vector multiply(const vector& a, const vector& b) { int n = a.size(), m = b.size(); if (!n || !m) return {}; if (min(n, m) < 32) { vector ans(n + m - 1); for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) ans[i + j] = (ans[i + j] + a[i] * b[j] % mod) % mod; return ans; } int lg = 0; while ((1 << lg) < n + m - 1) lg++; int z = 1 << lg; auto a2 = a; a2.resize(z); butterfly(false, a2); if (a == b) { for (int i = 0; i < z; i++) a2[i] = a2[i] * a2[i] % mod; } else { auto b2 = b; b2.resize(z); butterfly(false, b2); for (int i = 0; i < z; i++) a2[i] = a2[i] * b2[i] % mod; } butterfly(true, a2); a2.resize(n + m - 1); long long iz = modinv(z, mod); for (int i = 0; i < n + m - 1; i++) a2[i] = a2[i] * iz % mod; return a2; } Vec(P, long long, 200000, 0); vector divide_and_solve(int left, int right) {//f_l(x)からf_r(x)までの積 if(right - left == 1) { Vec(v, long long, 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); return multiply(vl, vr); } int main(){ ios::sync_with_stdio(false); cin.tie(0); long long N, M; cin >> N >> M; P.resize(N); rep(i, 0, N) { cin >> P[i]; P[i]--; P[i] %= mod; } auto ans = divide_and_solve(0, N); rep(i, 0, M){ int num = 0; cin >> num; cout << ans[N - num] % mod << endl; } }