luogu#P10586. 「ALFR Round 2」B 篮球比赛

「ALFR Round 2」B 篮球比赛

Background

Problem Description

Xiaoshan is going to play nn basketball matches. He has a polynomial function f(x)=a0+a1x1+a2x2++akxkf(x)=a_0+a_1x^1+a_2x^2+\dots+a_kx^k and mm numbers p1,p2,p3,,pmp_1,p_2,p_3,\dots,p_m whose sum is 11.

His team has a probability of f(i)j=1nf(j)\dfrac{f(i)}{\sum_{j=1}^n f(j)} to get the first victory in the ii-th match, which means they lost all of the first i1i-1 matches.

Next, if Xiaoshan’s team wins the ii-th match, then for 1jm1\le j\le m, they have probability pjp_j to get the next victory in the (i+j)(i+j)-th match. This means that if j>1j\gt1, they lose from match (i+1)(i+1) to match (i+j1)(i+j-1) (if i+j>ni+j>n, then all matches after that are losses and there will be no more victories).

Xiaoshan wants to know the expected number of wins of his team. Can you help him?

Note: During calculation, if you meet fractions (such as f(i)j=1nf(j)\dfrac{f(i)}{\sum_{j=1}^n f(j)}), you should use the “fraction modulo” form. If you do not know what “fraction modulo” means, see P2613 Template: Modulo of Rational Numbers.

To make computation easier, the input will directly give pi,aip_i,a_i after taking modulo 998244353998244353.

Input Format

The first line contains three integers n,m,kn, m, k, with meanings as described above.

The second line contains mm integers. The ii-th integer is the value of pip_i modulo 998244353998244353.

The third line contains k+1k + 1 integers. The ii-th integer is the value of ai1a_{i - 1} modulo 998244353998244353.

Note that pp is given before aa.

Output Format

Output one number in one line, the answer modulo 998244353998244353.

4 3 3
598946612 898419918 499122177
998244308 79 998244317 5
319837492

Hint

Sample Explanation

In the first sample: p1=0.2,p2=0.3,p3=0.5p_1=0.2,p_2=0.3,p_3=0.5; f(1)=3,f(2)=9,f(3)=3,f(4)=15f(1)=3,f(2)=9,f(3)=3,f(4)=15. The expected number of wins is 1.29881.2988.

Constraints

Subtask Score Limit
00 1010 n=1n=1
11 3030 n106n\le10^6
22 6060 -

For 100%100\% of the testdata, 1n10181\le n\le 10^{18}, 1m,k501\le m,k \le 50, and it is guaranteed that j=1nf(j)\sum_{j=1}^n f(j) is not divisible by 998244353998244353.

Translated by ChatGPT 5