#P4705. 玩游戏

    ID: 3543 远端评测题 3000ms 500MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>数学O2优化分治期望快速傅里叶变换 FFT洛谷月赛

玩游戏

Description

Alice and Bob are playing a game again.

In one game, first Alice receives a sequence aa of length nn, and Bob receives a sequence bb of length mm. Then they each randomly pick one number from their own sequence, denoted ax,bya_x, b_y. The kk-th value of this game is defined as (ax+by)k(a_x + b_y)^k.

Because they find this game too boring, they ask you to compute, for i=1,2,,ti = 1, 2, \cdots, t, the expected ii-th value of a game.

Since the answer can be large, you only need to output the result modulo 998244353998244353.

Input Format

The first line contains two integers n,m(1n,m105)n, m(1 \leq n, m \leq 10^5), representing the lengths of Alice’s and Bob’s sequences.

The next line contains nn numbers, where the ii-th number is ai(0ai<998244353)a_i(0 \leq a_i < 998244353), representing Alice’s sequence.

The next line contains mm numbers, where the jj-th number is bj(0bj<998244353)b_j(0 \leq b_j < 998244353), representing Bob’s sequence.

The next line contains one integer t(1t105)t(1 \leq t \leq 10^5), as described above.

Output Format

Output tt lines, where the ii-th line is the expected ii-th value of a single game.

1 1
1
2
3
3
9
27
2 8
764074134 743107904
663532060 183287581 749169979 7678045 393887277 27071620 13482818 125504606
6
774481679
588343913
758339354
233707576
36464684
461784746

Hint

Translated by ChatGPT 5