#include #include #include #include #include #include template inline bool chmin(T &lhs, const U &rhs) { if (lhs > rhs) { lhs = rhs; return true; } return false; } template inline bool chmax(T &lhs, const U &rhs) { if (lhs < rhs) { lhs = rhs; return true; } return false; } // [l, r) from l to r struct range { struct itr { int i; constexpr itr(int i_): i(i_) { } constexpr void operator ++ () { ++i; } constexpr int operator * () const { return i; } constexpr bool operator != (itr x) const { return i != x.i; } }; const itr l, r; constexpr range(int l_, int r_): l(l_), r(std::max(l_, r_)) { } constexpr itr begin() const { return l; } constexpr itr end() const { return r; } }; // [l, r) from r to l struct revrange { struct itr { int i; constexpr itr(int i_): i(i_) { } constexpr void operator ++ () { --i; } constexpr int operator * () const { return i; } constexpr bool operator != (itr x) const { return i != x.i; } }; const itr l, r; constexpr revrange(int l_, int r_): l(l_ - 1), r(std::max(l_, r_) - 1) { } constexpr itr begin() const { return r; } constexpr itr end() const { return l; } }; template class modular { public: using value_type = uint32_t; using max_type = uint64_t; static constexpr value_type mod = Modulus; static constexpr value_type mod_min = 1; static constexpr value_type mod_max = 2147483647; static_assert(mod >= mod_min, "invalid mod :: too small"); static_assert(mod <= mod_max, "invalid mod :: too big"); template static constexpr value_type normalize(T value_) { if (value_ < 0) { value_ = -value_; value_ %= mod; if (value_ == 0) return 0; return mod - value_; } return value_ % mod; } private: value_type value; public: constexpr modular(): value(0) { } template explicit constexpr modular(T value_): value(normalize(value_)) { } template explicit constexpr operator T() { return static_cast(value); } constexpr value_type operator () () const { return value; } constexpr modular operator - () const { return modular(mod - value); } constexpr modular operator ~ () const { return inverse(); } constexpr value_type &extract() { return value; } constexpr modular inverse() const { return power(mod - 2); } constexpr modular power(max_type exp) const { modular res(1), mult(*this); while (exp > 0) { if (exp & 1) res *= mult; mult *= mult; exp >>= 1; } return res; } constexpr modular operator + (const modular &rhs) const { return modular(*this) += rhs; } constexpr modular& operator += (const modular &rhs) { if ((value += rhs.value) >= mod) value -= mod; return *this; } constexpr modular operator - (const modular &rhs) const { return modular(*this) -= rhs; } constexpr modular& operator -= (const modular &rhs) { if ((value += mod - rhs.value) >= mod) value -= mod; return *this; } constexpr modular operator * (const modular &rhs) const { return modular(*this) *= rhs; } constexpr modular& operator *= (const modular &rhs) { value = (max_type) value * rhs.value % mod; return *this; } constexpr modular operator / (const modular &rhs) const { return modular(*this) /= rhs; } constexpr modular& operator /= (const modular &rhs) { return (*this) *= rhs.inverse(); } constexpr bool zero() const { return value == 0; } constexpr bool operator == (const modular &rhs) const { return value == rhs.value; } constexpr bool operator != (const modular &rhs) const { return value != rhs.value; } friend std::ostream& operator << (std::ostream &stream, const modular &rhs) { return stream << rhs.value; } }; using modint = modular<998244353>; int main() { int N, Q; std::cin >> N >> Q; std::vector A(N); for (auto &x: A) { std::cin >> x; } std::array, 2> dp{}; dp.fill(std::vector(N + 1)); dp[0][0] = modint(1); for (int i: range(0, N)) { auto &cur = dp[i & 1]; auto &next = dp[(i + 1) & 1]; for (int j: range(0, N + 1)) { if (j + 1 <= N) { next[j + 1] += cur[j]; } next[j] += cur[j] * modint(A[i] - 1); cur[j] = modint(0); } } const auto &ans = dp[N & 1]; while (Q--) { int x; std::cin >> x; std::cout << ans[x] << '\n'; } return 0; }