#P7509. 撕裂抹消
撕裂抹消
Description
Given an integer sequence of length , and a rational sequence . At each position there is a random coefficient , where and .
Note that when writing the random coefficients as a sequence, it can be divided into several maximal consecutive segments of and . “Maximal” means it cannot be extended to either side. Define the value (weight) of a coefficient sequence as follows: if the coefficient sequence has exactly maximal consecutive segments of , then its value is ; otherwise, its value is .
Find the expected value of this coefficient sequence. Output the answer modulo .
Input Format
The first line contains two positive integers .
The second line contains non-negative integers .
The third line contains non-negative integers , given modulo .
Output Format
One line with one non-negative integer, representing the expectation.
5 1
1 2 3 4 5
1 1 1 1 1
15
3 2
1 2 3
499122177 499122177 499122177
499122177
Hint
Sample Explanation
For the first sample, must be , and there must be exactly maximal consecutive segment, so the value must be .
For the second sample, the value is non-zero only when , and the probability of this case is $\frac 12 \times \frac 12 \times \frac 12 = \frac 18$, so the expectation is $\frac{1+3}8 = \frac 12 \equiv 499122177 \pmod {998244353}$.
Constraints
For of the testdata, .
For of the testdata, .
For of the testdata, , $1 \le k \le \min\left(20,\left\lfloor\frac{n+1}2\right\rfloor\right)$, .
Translated by ChatGPT 5
京公网安备 11011102002149号