1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198
|
#include <cctype> #include <cstdio> #include <algorithm> using namespace std;
namespace IO { const int MAXSIZE = 1 << 18 | 1; char buf[MAXSIZE], *p1, *p2;
inline int Gc() { return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, MAXSIZE, stdin), p1 == p2)? EOF: *p1++; } template<typename T> inline void read(T& x) { x = 0; int f = 0, ch = Gc(); while (!isdigit(ch)) f |= ch == '-', ch = Gc(); while (isdigit(ch)) x = x * 10 + ch - '0', ch = Gc(); if (f) x = -x; } } using IO::read;
const int LOG = 16, MAXN = 1 << LOG | 1, P = 998244353, G = 3;
int W[LOG][MAXN]; int inv[MAXN], fac[MAXN], ifac[MAXN];
int fpow(int base, int b) { int ret = 1; while (b > 0) { if (b & 1) ret = 1LL * ret * base % P; base = 1LL * base * base % P, b >>= 1; } return ret; }
inline void OutPoly(const int* f, const int& n) { for (int i = 0; i < n; ++i) fprintf(stderr, "%d%c", f[i], " \n"[i == n - 1]); }
namespace Poly { int r[MAXN]; inline void init(const int& Lim, const int& L) { for (int i = 1; i < Lim; ++i) r[i] = (r[i>>1] >> 1) | ((i & 1) << (L-1)); }
void NTT(int* f, const int& Lim, const int& type) { for (int i = 1; i < Lim; ++i) if (i < r[i]) swap(f[i], f[r[i]]); for (int k = 0, Mid = 1; Mid < Lim; ++k, Mid <<= 1) { const int* w = W[k]; for (int i = 0; i < Lim; i += Mid << 1) for (int j = 0; j < Mid; ++j) { int f0 = f[i+j], f1 = 1LL * w[j] * f[i+j+Mid] % P; f[i+j] = (f0 + f1) % P, f[i+j+Mid] = (f0 - f1 + P) % P; } } if (type < 0) { int iv = fpow(Lim, P - 2); for (int i = 0; i < Lim; ++i) f[i] = 1LL * f[i] * iv % P; reverse(f + 1, f + Lim); } }
void Inv(int* f, int* g, const int& n) { static int A[MAXN], B[MAXN]; g[0] = fpow(f[0], P - 2); for (int L = 0, Lim = 1, Mid = 2; Mid < 2*n; Mid <<= 1) { while (Lim < 2*Mid) Lim <<= 1, ++L; for (int i = 0; i < Mid; ++i) A[i] = f[i], B[i] = g[i]; for (int i = Mid; i < Lim; ++i) A[i] = B[i] = 0; init(Lim, L), NTT(A, Lim, 1), NTT(B, Lim, 1); for (int i = 0; i < Lim; ++i) g[i] = ((B[i] + B[i]) % P - 1LL * A[i] * B[i] % P * B[i] % P + P) % P; NTT(g, Lim, -1); for (int i = min(n, Mid); i < Lim; ++i) g[i] = 0; } }
inline void Der(int* f, int* g, const int& n) { for (int i = 1; i < n; ++i) g[i - 1] = 1LL * i * f[i] % P; g[n - 1] = 0; } inline void Int(int* f, int* g, const int& n) { for (int i = n - 1; i; --i) g[i] = 1LL * inv[i] * f[i - 1] % P; g[0] = 0; }
void Ln(int* f, int* g, const int& n) { static int ivf[MAXN], df[MAXN]; Der(f, df, n), Inv(f, ivf, n); int Lim = 1, L = 0; while (Lim < 2*n) Lim <<= 1, ++L; for (int i = n; i < Lim; ++i) ivf[i] = df[i] = 0; init(Lim, L), NTT(df, Lim, 1), NTT(ivf, Lim, 1); for (int i = 0; i < Lim; ++i) df[i] = 1LL * df[i] * ivf[i] % P; NTT(df, Lim, -1), Int(df, g, n); }
void Exp(int* f, int* g, const int& n) { static int lng[MAXN], A[MAXN], B[MAXN]; g[0] = 1; for (int L = 0, Lim = 1, Mid = 2; Mid < 2*n; Mid <<= 1) { Ln(g, lng, Mid); while (Lim < 2*Mid) Lim <<= 1, ++L; for (int i = 0; i < Mid; ++i) A[i] = (f[i] - lng[i] + P) % P, B[i] = g[i]; A[0] = (A[0] + 1) % P; for (int i = Mid; i < Lim; ++i) A[i] = B[i] = 0; init(Lim, L), NTT(A, Lim, 1), NTT(B, Lim, 1); for (int i = 0; i < Lim; ++i) g[i] = 1LL * A[i] * B[i] % P; NTT(g, Lim, -1); for (int i = min(n, Mid); i < Lim; ++i) g[i] = 0; } }
void Mul(int* f, const int& n, int* g, const int& m, int* h) { static int A[MAXN], B[MAXN]; int Lim = 1, L = 0; while (Lim < n + m - 1) Lim <<= 1, ++L; for (int i = 0; i < Lim; ++i) A[i] = (i < n)? f[i]: 0, B[i] = (i < m)? g[i]: 0; init(Lim, L), NTT(A, Lim, 1), NTT(B, Lim, 1); for (int i = 0; i < Lim; ++i) h[i] = 1LL * A[i] * B[i] % P; NTT(h, Lim, -1); } }
void PolyPre(int N) { inv[0] = inv[1] = fac[0] = ifac[0] = 1; for (int i = 2; i <= N; ++i) inv[i] = 1LL * inv[P % i] * (P - P / i) % P; for (int i = 1; i <= N; ++i) { fac[i] = 1LL * i * fac[i - 1] % P; ifac[i] = 1LL * inv[i] * ifac[i - 1] % P; } for (int w, i = 0, Mid = 1; i < LOG; ++i, Mid <<= 1) { W[i][0] = 1, w = fpow(G, (P - 1) / (Mid << 1)); for (int j = 1; j < Mid; ++j) W[i][j] = 1LL * w * W[i][j - 1] % P; } }
int n, m; int a[MAXN];
int tmp[LOG << 1][MAXN], ptr;
int solve(int* f, int L, int R) { if (R - L < 2) return f[0] = 1, f[1] = (P - a[L]) % P, 2; int Mid = (L + R) / 2, *f0 = tmp[ptr++], *f1 = tmp[ptr++]; int dl = solve(f0, L, Mid), dr = solve(f1, Mid, R); Poly::Mul(f0, dl, f1, dr, f), ptr -= 2; return dl + dr - 1; }
int A[MAXN], B[MAXN], ivB[MAXN]; int f[MAXN], g[MAXN];
int main() { #ifndef ONLINE_JUDGE freopen("input.in", "r", stdin); #endif read(n), read(m); for (int i = 1; i <= n; ++i) read(a[i]); if (n == 1) return puts((m == 0)? "1": "0"), 0; PolyPre(n); for (int i = 0; i <= n; ++i) { A[i] = 1LL * ifac[i] * fpow(i + 1, 2 * m) % P; B[i] = 1LL * ifac[i] * fpow(i + 1, m) % P; } Poly::Inv(B, ivB, n + 1), Poly::Ln(B, B, n + 1); Poly::Mul(A, n + 1, ivB, n + 1, A); solve(g, 1, n + 1); Poly::Ln(g, g, n + 1); for (int i = 1; i <= n; ++i) g[i] = (P - 1LL * g[i] * i % P) % P; g[0] = n; for (int i = 0; i <= n; ++i) A[i] = 1LL * A[i] * g[i] % P, B[i] = 1LL * B[i] * g[i] % P; Poly::Exp(B, f, n + 1); Poly::Mul(f, n + 1, A, n + 1, f); int ans = 1LL * fac[n - 2] * f[n - 2] % P; for (int i = 1; i <= n; ++i) ans = 1LL * ans * a[i] % P; printf("%d\n", ans); return 0; }
|