「解题报告」[ARC106D] Powers
考虑容斥。
后边预处理出来,考虑使用二项式定理化简一下前边的。
那么对于所有的 预处理出来 即可。
时间复杂度 。
const ll N = 2e5 + 10, K = 310, P = 998244353;
namespace SOLVE {
ll n, k, a[N], b[2][K], c[K][K], ans[K];
inline ll rnt () {
ll x = 0, w = 1; char c = getchar ();
while (!isdigit (c)) { if (c == '-') w = -1; c = getchar (); }
while (isdigit (c)) x = (x << 3) + (x << 1) + (c ^ 48), c = getchar ();
return x * w;
}
inline ll FastPow (ll a, ll b) {
ll ans = 1;
while (b) {
if (b & 1) ans = ans * a % P;
a = a * a % P, b >>= 1;
}
return ans;
}
inline void In () {
n = rnt (), k = rnt ();
_for (i, 1, n) a[i] = rnt ();
return;
}
inline void Solve () {
c[0][0] = 1, b[0][0] = b[1][0] = n;
_for (j, 1, k) {
_for (i, 1, n) {
b[0][j] = (b[0][j] + FastPow (a[i], j)) % P;
b[1][j] = (b[1][j] + FastPow (a[i] << 1, j)) % P;
}
}
_for (i, 1, k) {
c[i][0] = 1, ans[i] = b[0][0] * b[0][i] % P;
_for (j, 1, i) {
c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % P;
ans[i] = (ans[i] + c[i][j] * b[0][j] % P * b[0][i - j] % P) % P;
}
ans[i] = (ans[i] - b[1][i] + P) % P * 499122177 % P;
}
return;
}
inline void Out () {
_for (i, 1, k) printf ("%lld\n", ans[i]);
return;
}
}