#pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #pragma GCC optimize("inline") #pragma GCC target("avx2") #include #include #include #include #include #include #include #include #include #include namespace fastio { #ifdef MY_DEBUG #define fread_unlocked fread #define fwrite_unlocked fwrite #endif static constexpr int SZ = 1 << 17; char ibuf[SZ], obuf[SZ]; int pil = 0, pir = 0, por = 0; inline void load() { memcpy(ibuf, ibuf + pil, pir - pil); pir = pir - pil + fread_unlocked(ibuf + pir - pil, 1, SZ - pir + pil, stdin); pil = 0; } inline void rd(char &c) { if (pil + 32 > pir) load(); c = ibuf[pil++]; } template inline void rd(T &x) { if (pil + 32 > pir) load(); char c; do c = ibuf[pil++]; while (c < '-'); [[maybe_unused]] bool minus = false; if constexpr (std::is_signed::value == true) { if (c == '-') minus = true, c = ibuf[pil++]; } x = 0; while (c >= '0') { x = x * 10 + (c & 15); c = ibuf[pil++]; } if constexpr (std::is_signed::value == true) { if (minus) x = -x; } } inline void rd() {} template inline void rd(Head &head, Tail &... tail) { rd(head); rd(tail...); } inline void skip_space() { if (pil + 32 > pir) load(); while (ibuf[pil] <= ' ') pil++; } inline void flush() { fwrite_unlocked(obuf, 1, por, stdout); por = 0; } struct Pre { char num[40000]; constexpr Pre() : num() { for (int i = 0; i < 10000; i++) { int n = i; for (int j = 3; j >= 0; j--) { num[i * 4 + j] = n % 10 + '0'; n /= 10; } } } } constexpr pre; struct Post { Post() { std::atexit(flush); } } post; inline void wt(char c) { if (por > SZ - 32) flush(); obuf[por++] = c; } inline void wt(bool b) { if (por > SZ - 32) flush(); obuf[por++] = b ? '1' : '0'; } template inline void wt(T x) { if (por > SZ - 32) flush(); if (!x) { obuf[por++] = '0'; return; } if constexpr (std::is_signed::value == true) { if (x < 0) obuf[por++] = '-', x = -x; } int i = 12; char buf[16]; while (x >= 10000) { memcpy(buf + i, pre.num + (x % 10000) * 4, 4); x /= 10000; i -= 4; } if (x < 100) { if (x < 10) { obuf[por] = '0' + x; ++por; } else { uint32_t q = (uint32_t(x) * 205) >> 11; uint32_t r = uint32_t(x) - q * 10; obuf[por] = '0' + q; obuf[por + 1] = '0' + r; por += 2; } } else { if (x < 1000) { memcpy(obuf + por, pre.num + (x << 2) + 1, 3); por += 3; } else { memcpy(obuf + por, pre.num + (x << 2), 4); por += 4; } } memcpy(obuf + por, buf + i + 4, 12 - i); por += 12 - i; } inline void wt() {} template inline void wt(Head &&head, Tail &&... tail) { wt(head); wt(std::forward(tail)...); } template inline void wtn(Args &&... x) { wt(std::forward(x)...); wt('\n'); } } // namespace fastio using fastio::rd; using fastio::wtn; using namespace std; using Mint = atcoder::modint998244353; vector q[12000]; int main() { int N, Q; rd(N, Q); int li = 0, ri = 0; for (int a; ri < N; ++ri) { rd(a); q[ri] = vector{Mint(a - 1), Mint(1)}; } while (ri - li > 1) { q[ri++] = atcoder::convolution(move(q[li]), move(q[li + 1])); li += 2; } const auto &f = q[li]; for (int i = 0, b; i < Q; ++i) { rd(b); wtn(f[b].val()); } }