Description
Solution
设
A=∑wi,B=∑i is deadwi
A
=
∑
w
i
,
B
=
∑
i
i
s
d
e
a
d
w
i
,那么
i
i
下一轮死亡的概率为.
假设我们可以鞭尸,那么下一轮死亡的概率为
P′=P′BA+wiA
P
′
=
P
′
B
A
+
w
i
A
.(如果打中了已经死亡的人,那么下下轮还是有
P′
P
′
的概率死亡)
我们解得:
P′=wiA−B
P
′
=
w
i
A
−
B
.
是的,我们发现
P=P′
P
=
P
′
,也就是我们可以不考虑只能打存活的人的限制,不影响答案.
我们枚举一个不包括
1
1
的集合,表示有哪些人在
1
1
的后面死亡,简单容斥一下,得到它们对答案的贡献为:
(其中 sum s u m 为 S S 的之和)
我们对这个无限等比数列求和,化简得:
发现 ∑wi ∑ w i 比较小,我们可以用NTT来搞这个,每一个 wi w i 代表一个多项式, 0 0 位置上为, wi w i 位置上为 −1 − 1 ,这样将所有多项式乘起来后第 i i 项系数即为值为的系数和.我们将最高次小的多项式先合并,时间复杂度 O(∑wi×log2) O ( ∑ w i × log 2 ) .
Code
/**************************************
* Au: Hany01
* Prob: LOJ2541
* Date: Aug 26th, 2018
* Email: hany01@foxmail.com
**************************************/
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
#define File(a) freopen(a".in", "r", stdin), freopen(a".out", "w", stdout)
#define rep(i, j) for (register int i = 0, i##_end_ = j; i < i##_end_; ++ i)
#define For(i, j ,k) for (register int i = (j), i##_end_ = (k); i <= i##_end_; ++ i)
#define Fordown(i, j, k) for (register int i = (j), i##_end_ = (k); i >= i##_end_; -- i)
#define Set(a, b) memset(a, b, sizeof(a))
#define Cpy(a, b) memcpy(a, b, sizeof(a))
#define SZ(a) ((int)(a.size()))
#define ALL(a) a.begin(), a.end()
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define x first
#define y second
#define INF (0x3f3f3f3f)
#define INF1 (2139062143)
#define MOD 998244353
#define y1 wozenmezhemecaia
#ifdef hany01
#define debug(...) fprintf(stderr, __VA_ARGS__)
#else
#define debug(...)
#endif
template<typename T> inline bool chkmax(T &a, T b) { return a < b ? a = b, 1 : 0; }
template<typename T> inline bool chkmin(T &a, T b) { return b < a ? a = b, 1 : 0; }
inline int read() {
register char c_; register int _, __;
for (_ = 0, __ = 1, c_ = getchar(); !isdigit(c_); c_ = getchar()) if (c_ == '-') __ = -1;
for ( ; isdigit(c_); c_ = getchar()) _ = (_ << 1) + (_ << 3) + (c_ ^ 48);
return _ * __;
}
const int maxn = 1e5 + 5;
int n, w1, w[maxn], sumw = 1, rev[maxn << 2], powg[maxn << 2], ipowg[maxn << 2], Ans, inv3;
struct Poly { VI a; }t1, t2, fin;
VI tmp;
inline bool operator < (Poly A, Poly B) { return SZ(A.a) > SZ(B.a); }
priority_queue<Poly> q;
inline int ad(int x, int y) { if ((x += y) >= MOD) return x - MOD; return x; }
inline int Pow(int a, int b) {
static int Ans;
for (Ans = 1; b; b >>= 1, a = (LL)a * a % MOD) if (b & 1) Ans = (LL)Ans * a % MOD;
return Ans;
}
inline void NTT(int* a, int n, int ty) {
rep(i, n) if (i < rev[i]) swap(a[i], a[rev[i]]);
for (register int i = 2, p = 1; i <= n; p = i, i <<= 1) {
register int w0 = ty > 0 ? powg[i] : ipowg[i];
for (register int j = 0; j < n; j += i) {
register int w = 1;
rep(k, p) {
register int x = a[j + k], y = (LL)a[j + k + p] * w % MOD;
a[j + k] = ad(x, y), a[j + k + p] = ad(x, MOD - y);
w = (LL)w * w0 % MOD;
}
}
}
if (ty < 1) {
register int invn = Pow(n, MOD - 2);
rep(i, n) a[i] = (LL)a[i] * invn % MOD;
}
}
inline Poly Mult(Poly A, Poly B) {
static int n1, n2, n, N, cnt, p[maxn << 1], q[maxn << 1];
static Poly C;
for (n1 = SZ(A.a), n2 = SZ(B.a), n = n1 + n2 - 1, N = 1, cnt = 0; N < n; N <<= 1, ++ cnt);
rep(i, N) p[i] = i < n1 ? A.a[i] : 0, q[i] = i < n2 ? B.a[i] : 0;
rep(i, N) rev[i] = (rev[i >> 1] >> 1) | ((i & 1) << (cnt - 1));
NTT(p, N, 1), NTT(q, N, 1);
rep(i, N) p[i] = (LL)p[i] * q[i] % MOD;
NTT(p, N, -1), C.a.resize(n);
rep(i, n) C.a[i] = p[i];
return C;
}
int main()
{
#ifdef hany01
File("loj2541");
#endif
n = read() - 1, w1 = read();
For(i, 1, n) sumw += (w[i] = read()), tmp.resize(0), tmp.resize(w[i] + 1), tmp[0] = 1, tmp[w[i]] = MOD - 1, q.push((Poly){tmp});
inv3 = Pow(3, MOD - 2);
for (int i = 1; i <= (sumw << 1); i <<= 1) powg[i] = Pow(3, (MOD - 1) / i), ipowg[i] = Pow(inv3, (MOD - 1) / i);
For(T, 1, n - 1) t1 = q.top(), q.pop(), t2 = q.top(), q.pop(), q.push(Mult(t1, t2));
rep(i, SZ((fin = q.top()).a)) Ans = ad(Ans, (LL)fin.a[i] * w1 % MOD * Pow(i + w1, MOD - 2) % MOD);
printf("%d\n", Ans);
return 0;
}