#define MOD_TYPE 2 #pragma region Macros #include using namespace std; #if 0 #include #include using Int = boost::multiprecision::cpp_int; using lld = boost::multiprecision::cpp_dec_float_100; #endif #if 0 #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #endif using ll = long long int; using ld = long double; using pii = pair; using pll = pair; using pld = pair; template using smaller_queue = priority_queue, greater>; constexpr ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353); constexpr int INF = (int)1e9 + 10; constexpr ll LINF = (ll)4e18; constexpr double PI = acos(-1.0); constexpr double EPS = 1e-7; constexpr int Dx[] = {0, 0, -1, 1, -1, 1, -1, 1, 0}; constexpr int Dy[] = {1, -1, 0, 0, -1, -1, 1, 1, 0}; #define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i) #define rep(i, n) REP(i, 0, n) #define REPI(i, m, n) for (int i = m; i < (int)(n); ++i) #define repi(i, n) REPI(i, 0, n) #define MP make_pair #define MT make_tuple #define YES(n) cout << ((n) ? "YES" : "NO") << "\n" #define Yes(n) cout << ((n) ? "Yes" : "No") << "\n" #define possible(n) cout << ((n) ? "possible" : "impossible") << "\n" #define Possible(n) cout << ((n) ? "Possible" : "Impossible") << "\n" #define all(v) v.begin(), v.end() #define NP(v) next_permutation(all(v)) #define dbg(x) cerr << #x << ":" << x << "\n"; struct io_init { io_init() { cin.tie(0); ios::sync_with_stdio(false); cout << setprecision(30) << setiosflags(ios::fixed); }; } io_init; template inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } inline ll CEIL(ll a, ll b) { return (a + b - 1) / b; } template inline void Fill(A (&array)[N], const T &val) { fill((T *)array, (T *)(array + N), val); } template constexpr istream &operator>>(istream &is, pair &p) noexcept { is >> p.first >> p.second; return is; } template constexpr ostream &operator<<(ostream &os, pair &p) noexcept { os << p.first << " " << p.second; return os; } #pragma endregion ll mod_pow(ll a, ll n, ll m) { ll res = 1, p = a % m; while (n) { if (n & 1) res = res * p % m; p = p * p % m; n >>= 1; } return res; } template //特殊な素数と原始根 998244353のとき3 class NTT { private: template inline void bit_reverse(vector &a) { int n = a.size(); int i = 0; for (int j = 1; j < n - 1; ++j) { for (int k = n >> 1; k > (i ^= k); k >>= 1) ; if (j < i) swap(a[i], a[j]); } } void _ntt(vector &a, int sign) { const int n = a.size(); assert((n ^ (n & -n)) == 0); //n = 2^k long long tmp = (mod - 1) * mod_pow((ll)n, mod - 2, mod) % mod; // -1/n long long h = mod_pow(root, tmp, mod); // ^n√g if (sign == -1) h = mod_pow(h, mod - 2, mod); bit_reverse(a); for (ll m = 1; m < n; m <<= 1) { const ll m2 = 2 * m; long long _base = mod_pow((ll)h, (ll)(n / m2), mod); long long _w = 1; for (int x = 0; x < m; ++x) { for (ll s = x; s < n; s += m2) { long long u = a[s]; long long d = (a[s + m] * _w) % mod; a[s] = (u + d) % mod; a[s + m] = (u - d + mod) % mod; } _w = (_w * _base) % mod; } } } void ntt(vector &input) { _ntt(input, 1); } void intt(vector &input) { _ntt(input, -1); const long long n_inv = mod_pow((ll)input.size(), mod - 2, mod); for (auto &x : input) x = (x * n_inv) % mod; } public: // 畳み込み演算を行う vector convolution(const vector &a, const vector &b) { int result_size = a.size() + b.size() - 1; int n = 1; while (n < result_size) n <<= 1; vector _a = a, _b = b; _a.resize(n, 0); _b.resize(n, 0); ntt(_a); ntt(_b); for (int i = 0; i < n; ++i) _a[i] = (_a[i] * _b[i]) % mod; intt(_a); _a.resize(result_size); return _a; } }; template class SegmentTree { private: using Fn = function; int N; vector dat; T unit; Fn func; public: SegmentTree() {} SegmentTree(int n_, Fn func_, T unit_) : func(func_), unit(unit_) { N = 1; while (N < n_) N *= 2; dat.assign(2 * N - 1, unit); } SegmentTree(const vector &v, Fn func_, T unit_) : func(func_), unit(unit_) { N = 1; int sz = v.size(); while (N < sz) N *= 2; dat.resize(2 * N - 1); for (int i = 0; i < N; ++i) dat[i + N - 1] = (i < sz ? v[i] : unit); for (int i = N - 2; i >= 0; --i) dat[i] = func(dat[i * 2 + 1], dat[i * 2 + 2]); } void update(int k, T a) { k += N - 1; dat[k] = a; while (k > 0) { k = (k - 1) / 2; dat[k] = func(dat[k * 2 + 1], dat[k * 2 + 2]); } } T get(int k) { return dat[k + N - 1]; } T query(int l, int r) { T vl = unit, vr = unit; for (l += (N - 1), r += (N - 1); l < r; l >>= 1, r >>= 1) { if ((l & 1) == 0) vl = func(vl, dat[l]); if ((r & 1) == 0) vr = func(vr, dat[--r]); } return func(vl, vr); } }; void solve() { NTT<> ntt; int n, q; cin >> n >> q; vector a(n); rep(i, n) { cin >> a[i]; a[i] %= MOD; } auto prod = [&](vector &f, vector &g) { if (f.size() == 1 and f[0] == 1) return g; if (g.size() == 1 and g[0] == 1) return f; return ntt.convolution(f, g); }; vector unit = {1}; vector> f(n, vector(2)); rep(i, n) { f[i][0] = a[i] - 1, f[i][1] = 1; } SegmentTree> sg(f, prod, unit); vector g = sg.query(0, n); rep(qi, q) { int b; cin >> b; cout << g[b] << "\n"; } } int main() { solve(); }