loj#P555. 「LibreOJ Round #8」抢红包

    ID: 15261 传统题 3000ms 256MiB 尝试: 0 已通过: 0 难度: (无) 上传者: 标签>DFT(含 NTT)及FFTDP概率与期望生成函数 / 母函数LibreOJ Round

「LibreOJ Round #8」抢红包

Description

Moejy0viiiiiv is collecting red envelopes on a rectangular plane. She starts at (0,0)(0,0). Every day at noon, she walks from (x,y)(x, y) to (x,y+1)(x,y+1) with probability A/1996488707A/1996488707, and to (x+1,y)(x+1,y) with probability B/1996488707B/1996488707, and stops immediately with probability 1A/1996488707B/19964887071-A/1996488707-B/1996488707 (once she stops, she will never move again). Besides, she also stops after walking for NN days.

With a given constant integer DD, there’s a red envelope at each (xD,yD)(0x,y)(xD, yD)(0 \leq x, y). There’re also KK barriers at $(x_1, y_1), (x_2, y_2), (x_3, y_3), ..., (x_K, y_K)$ (barriers never coincide with red envelopes). If she walks to a barrier, she will stop immediately.

Moejy0viiiiiv will collect each red envelope she passes by (including (0,0)(0,0)). What’s the expected number of red envelopes Moejy0viiiiiv collects after NN days? Output the answer mod998244353\bmod 998244353. Notice that 1996488707mod998244353=11996488707 \bmod 998244353 = 1.

Input Format

The first line contains two positive integers A,BA,B.

The second line contains four positive integers N,D,M,KN,D,M,K.

The following KK lines each contains two integers, the i+2i+2-th line contains xi,yix_i,y_i.

Output Format

Output contains one integer, the expected number of red envelopes mod998244353\bmod 998244353.

1 1
2 2 5 1
1 0
2
1 2
2 2 5 0
6

Constraints

For all test cases, $1 \leq N \leq 10^{18}, 0 \leq K \leq 50, 1 \leq D, M \leq 1000, 0 \leq x_1, x_2, ..., x_K \leq M$, $\forall i \in \{1, 2, 3, ..., K\}, D \nmid x_i \vee D \nmid y_i, x_i + y_i \leq N, 0 \leq A, B < 998244353$.

Detailed constraints are as follows (blank grids denote the same constraints as mentioned above):

Subtask # Score (percentage) NN DD MM KK
11 99 104\le 10^4 -
22 1212 105\le 10^5 10\le 10 00
33 2727 -
44 88 105\le 10^5 10\le 10 10\le 10 -
55 4444 -