设f(τ,i)表示第τ次操作进行之前,也就是第(τ−1)次操作进行之后得到的数是i的概率。那么f(1,i)=pi,我们需要对于每个i求出f(m+1,i)。
不要问我为什么用τ这个奇怪的字母
考虑一次操作带来的影响:显然有
f(τ+1,i)=j=i∑nj+1f(τ,j)
看起来不是很明显,我们利用生成函数来找关系。设Fτ(x)=i=0∑nf(τ,i)xi,那么
Fτ+1(x)=i=0∑nf(τ+1,i)xi
=i=0∑nj=i∑nj+1f(τ,j)xi
=j=0∑nj+1f(τ,j)i=0∑jxi
=j=0∑nj+1f(τ,j)⋅x−1xj+1−1
=x−11j=0∑nf(τ,j)j+1xj+1−1
=x−11j=0∑nf(τ,j)∫1xtjdt
=x−11∫1xFτ(t)dt
我们喜闻乐见的是∫0xf(t)dt=∫f(x)dx并且常数项为0。但这里积分下限是1,不好处理。
设Gτ(x)=Fτ(x+1),并且Gτ(x)=i=0∑ng(τ,i)xi,那么
Gτ+1(x)=x1∫1x+1Fτ(t)dt
=x1∫0xFτ(t+1)d(t+1)
=i=0∑ni+1g(τ,i)xi
于是我们发现
g(τ+1,i)=i+1g(τ,i)
这是等比数列。那么
g(m+1,i)=(i+1)mg(1,i)
下面的问题就是如何求出g(1,i),以及如何由g(m+1,i)求出f(m+1,i)。
∵Gτ(x)=Fτ(x+1)
∴i=0∑ng(τ,i)xi=i=0∑nf(τ,i)j=0∑iCijxj
=j=0∑nxji=j∑nf(τ,i)Cij
∴g(τ,i)=j=i∑nCjif(τ,j)
令τ=1,这时f(τ,i)=pi,那么
g(1,i)=j=i∑ni!(j−i)!j!pj
=i!1j=0∑n−ij!1(j+i)!pj+i
记ai=i!1,bi=(n−i)!pn−i,那么
g(1,i)=i!1j=0∑n−iajbn−i−j
NTT求卷积即可。
然后再考虑怎么求出f(m+1,i)。为了方便起见,将f(m+1,i)记为fi,将g(m+1,i)记为gi。
我们发现由f求出g的过程就是个卷积,现在要反过来求,我们需要多项式求逆吗?并不需要,只要一个反演即可。
∵gi=j=i∑nCjifj
∴fi=j=i∑n(−1)j−iCjigj
=i!1j=i∑n(j−i)!(−1)j−ij!gj
=i!1j=0∑n−ij!(−1)j(j+i)!gj+i
设ci=i!(−1)i,di=(n−i)!gn−i,那么
fi=i!1j=0∑n−icjdn−i−j
NTT求卷积即可。
时间复杂度O(nlogn)。
#include <cctype>
#include <cstdio>
#include <climits>
#include <algorithm>
template <typename T> inline void read(T& x) {
int f = 0, c = getchar(); x = 0;
while (!isdigit(c)) f |= c == '-', c = getchar();
while (isdigit(c)) x = x * 10 + c - 48, c = getchar();
if (f) x = -x;
}
template <typename T, typename... Args>
inline void read(T& x, Args&... args) {
read(x); read(args...);
}
template <typename T> void write(T x) {
if (x < 0) x = -x, putchar('-');
if (x > 9) write(x / 10);
putchar(x % 10 + 48);
}
template <typename T> inline void writeln(T x) { write(x); puts(""); }
template <typename T> inline bool chkmin(T& x, const T& y) { return y < x ? (x = y, true) : false; }
template <typename T> inline bool chkmax(T& x, const T& y) { return x < y ? (x = y, true) : false; }
typedef long long LL;
const LL mod = 998244353, G = 3, Gi = 332748118;
const int maxn = 1e5 + 7;
inline LL qpow(LL x, LL k) {
LL s = 1;
for (; k; x = x * x % mod, k >>= 1)
if (k & 1) s = s * x % mod;
return s;
}
inline void ntt(LL *A, int *r, int lim, int tp) {
for (int i = 0; i < lim; ++i)
if (i < r[i]) std::swap(A[i], A[r[i]]);
for (int mid = 1; mid < lim; mid <<= 1) {
LL wn = qpow(tp == 1 ? G : Gi, (mod - 1) / (mid << 1));
for (int j = 0; j < lim; j += mid << 1) {
LL w = 1;
for (int k = 0; k < mid; ++k, w = w * wn % mod) {
LL x = A[j + k], y = w * A[j + k + mid] % mod;
A[j + k] = (x + y) % mod;
A[j + k + mid] = (x - y + mod) % mod;
}
}
}
if (tp == -1) {
LL inv = qpow(lim, mod - 2);
for (int i = 0; i < lim; ++i)
A[i] = A[i] * inv % mod;
}
}
int n, r[maxn << 2], lim, l;
LL m, p[maxn], fac[maxn], ifac[maxn];
LL a[maxn << 2], b[maxn << 2], g[maxn];
int main() {
read(n, m);
for (int i = 0; i <= n; ++i) read(p[i]);
fac[0] = ifac[0] = 1;
for (int i = 1; i <= n + 1; ++i)
fac[i] = fac[i - 1] * i % mod;
ifac[n + 1] = qpow(fac[n + 1], mod - 2);
for (int i = n; i; --i)
ifac[i] = ifac[i + 1] * (i + 1) % mod;
for (int i = 0; i <= n; ++i) {
a[i] = ifac[i];
b[i] = fac[n - i] * p[n - i] % mod;
}
for (lim = 1; lim <= (n << 1); ++l) lim <<= 1;
for (int i = 0; i < lim; ++i)
r[i] = (r[i >> 1] >> 1) | ((i & 1) << (l - 1));
ntt(a, r, lim, 1); ntt(b, r, lim, 1);
for (int i = 0; i < lim; ++i)
a[i] = a[i] * b[i] % mod;
ntt(a, r, lim, -1);
for (int i = 0; i <= n; ++i)
g[i] = ifac[i] * a[n - i] % mod * qpow(qpow(i + 1, m), mod - 2) % mod;
for (int i = 0; i <= n; ++i) {
a[i] = ((i & 1) ? mod - 1 : 1ll) * ifac[i] % mod;
b[i] = fac[n - i] * g[n - i] % mod;
}
for (int i = n + 1; i < lim; ++i)
a[i] = b[i] = 0;
ntt(a, r, lim, 1); ntt(b, r, lim, 1);
for (int i = 0; i < lim; ++i)
a[i] = a[i] * b[i] % mod;
ntt(a, r, lim, -1);
for (int i = 0; i <= n; ++i)
write(ifac[i] * a[n - i] % mod), putchar(' ');
return 0;
}