#P4564. [CTSC2018] 假面

    ID: 3458 远端评测题 2000ms 500MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>数学2018WC/CTSC/集训队O2优化枚举,暴力期望

[CTSC2018] 假面

Description

Zhenzhen likes to play a game called DotA (Defense of the Algorithm). In this game, Zhenzhen controls his hero and fights alongside teammates against another team. Zhenzhen’s favorite hero in DotA is called “Faceless,” and this hero has 22 skills:

  • Lock: Cast on a specified enemy unit, dealing 11 point of damage (reducing its health by 11) with probability pp.
  • Barrier: Cast on an area to trap all other units in that area so they cannot move. In the game, if a unit’s health drops to 00 or below, that unit dies.

Zhenzhen is not very skilled at controlling Faceless, so he decides to practice diligently. There are nn enemy units (numbered from 11 to nn), and the enemy unit numbered ii has mim_i health points.

Zhenzhen has arranged a practice plan in which he will cast QQ skills in order:

  • For the Lock skill: Zhenzhen specifies an enemy unit idid and casts it on that unit. Since many factors determine the probability parameter pp, the value of pp may be different each time. In particular, if the specified enemy unit is already dead, then this skill has no effect.
  • For the Barrier skill: Zhenzhen intends to cast it on kk specified enemy units, but since he is not good at casting this skill, he can hit exactly 11 enemy unit. The probability of hitting each living enemy unit is equal (i.e., already dead enemy units have no effect). In particular, if all kk specified enemy units are already dead, then this skill also does not hit any unit.

Now, Lvlv, who is watching Zhenzhen practice, wants to know:

  1. For each Barrier skill that Zhenzhen casts, what is the probability that it hits each enemy, respectively.
  2. After all of Zhenzhen’s skills have been cast, what is the expected remaining health of each enemy unit.

To prevent precision errors, for all numerical outputs, please output their values modulo 998244353998244353.

Since Barrier is Faceless’s ultimate skill, the number of times Zhenzhen casts it will not be too many. See Constraints.

Input Format

The 11-st line contains 11 positive integer nn, the number of enemy units. The 22-nd line contains nn positive integers m1,,mnm_1, \cdots, m_n, representing the initial health of each enemy unit in order. The 33-rd line contains 11 non-negative integer QQ, the number of skills Zhenzhen will cast. The 44-th to the (Q+3)(Q + 3)-rd lines each describe one skill; the (i+3)(i + 3)-rd line describes the ii-th skill.

Each line begins with an integer opop, indicating the type of the skill. If op=0op = 0, it indicates the Lock skill. This is followed by 33 positive integers id,u,vid, u, v, meaning the target is idid, and the hit probability is p=uvp = \frac{u}{v}. (Guaranteed that 1idn1 \le id \le n, 0<uv<9982443530 < u \le v < 998244353.) If op=1op = 1, it indicates the Barrier skill. This is followed by 11 positive integer kk indicating the number of targets, then an additional kk numbers id1,,idkid_1, \cdots, id_k describing all the targets of this skill. (Guaranteed that all 1idin1 \le id_i \le n are pairwise distinct.) Within each line, if there are multiple numbers, separate them with a single space.

Output Format

Output C+1C + 1 lines (where CC is the number of Barrier skills):

For the first CC lines, corresponding to each Barrier skill in order: Output kk numbers. The ii-th number is the probability that the Barrier hits enemy unit idiid_i.

On the (C+1)(C + 1)-st line, output nn numbers. The ii-th number is the expected remaining health of enemy unit ii after all skills have been cast.

Within each line, if there are multiple numbers, separate them with a single space.

For all numerical values, output them modulo 998244353998244353: that is, suppose the answer in reduced fraction form is ab\frac{a}{b} with gcd(a,b)=1\gcd(a, b) = 1. Output the integer xx such that bxamod998244353b x \equiv a \bmod 998244353 and 0x<9982443530 \le x < 998244353. (It can be proven that such an integer xx is unique.)

3
1 2 3
6
0 2 1 1
1 1 2
0 2 1 1
0 3 1 1
1 1 2
1 3 1 2 3
1
0
499122177 0 499122177
1 0 2

3
1 1 1
4
0 2 1 2
1 2 1 2
0 3 2 3
1 3 1 2 3
249561089 748683265
804141285 887328314 305019108
1 499122177 332748118

Hint

Sample Explanation 1 Zhenzhen casts the following skills in order:

  1. Cast Lock on enemy unit 22: deals 11 damage with probability 11. At this moment, enemy unit 22 must have 11 health remaining.
  2. Cast Barrier on enemy unit 22: (since enemy unit 22 is still alive,) it must hit unit 22.
  3. Cast Lock on enemy unit 22: deals 11 damage with probability 11.
  4. Cast Lock on enemy unit 33: deals 11 damage with probability 11. Now the three enemy units’ health values must be 1,0,21, 0, 2 respectively, and enemy unit 22 must be dead.
  5. Cast Barrier on enemy unit 22: (since enemy unit 22 is dead,) it must hit no unit.
  6. Cast Barrier on enemy units 1,2,31, 2, 3: the probabilities of hitting enemy units 11 and 33 are equal, i.e., each 12\frac{1}{2}. Finally, the remaining health of the three enemy units must be 1,0,21, 0, 2.

Sample Explanation 2 Analysis for each Barrier skill:

  1. The 11-st Barrier (targets enemy units 1,21, 2):
  • The probability that enemy unit 22 is alive is 12\frac{1}{2}, and enemy unit 11 must be alive.
  • If enemy unit 22 is alive, then the probabilities of Barrier hitting 11 and 22 are equal, both 12\frac{1}{2}; if enemy unit 22 is dead, then Barrier must hit enemy unit 11.
  • Therefore: the probability of hitting enemy unit 11 is $\frac{1}{2} \times 1 + \frac{1}{2} \times \frac{1}{2} = \frac{3}{4}$; the probability of hitting enemy unit 22 is $\frac{1}{2} \times 0 + \frac{1}{2} \times \frac{1}{2} = \frac{1}{4}$.
  1. The 22-nd Barrier (targets enemy units 1,2,31, 2, 3):
  • The probabilities that the three enemy units are alive are 1,12,131, \frac{1}{2}, \frac{1}{3}, respectively.
  • The probability that 1,2,31, 2, 3 are all alive is 16\frac{1}{6}; the probability that only 1,21, 2 are alive is 13\frac{1}{3}; the probability that only 1,31, 3 are alive is 16\frac{1}{6}; the probability that only 11 is alive is 13\frac{1}{3}.
  • Therefore: the probability of hitting enemy unit 11 is $\frac{1}{6} \times \frac{1}{3} + (\frac{1}{3} + \frac{1}{6}) \times \frac{1}{2} + \frac{1}{3} \times 1 = \frac{23}{36}$; the probability of hitting enemy unit 22 is $\frac{1}{6} \times \frac{1}{3} + \frac{1}{3} \times \frac{1}{2} = \frac{2}{9}$; the probability of hitting enemy unit 33 is $\frac{1}{6} \times \frac{1}{3} + \frac{1}{6} \times \frac{1}{2} = \frac{5}{36}$. Finally, the expected remaining health of the three enemy units is 1,12,131, \frac{1}{2}, \frac{1}{3}.

Constraints

Let CC be the number of Barrier skills.

Test point id n = Q = C = u, v Other constraints
1 5 21 6 u < v None
2 60 199992 500 All pp are equal
3 23 6 All mi=1m_i = 1
4 199994 500 None
5 199995
6 199996 0
7 199997 500 u = v
8 200 199998 1000 u < v
9 199999
10 200000

For all test points, it is guaranteed that n200n \le 200, Q200000Q \le 200000, C1000C \le 1000, mi100m_i \le 100.

Hint

The units digit of QQ can help you quickly determine the test point id. The test point order may not correlate with difficulty.

Thanks to @和泉正宗 for providing the statement.

Translated by ChatGPT 5