#abc242h. Ex - Random Painting

Ex - Random Painting

Score : 600600 points

问题描述

设有编号从 11NNNN 个正方形,最初所有正方形都被涂成白色。

另外,盒子中有编号从 11MMMM 个球。

我们按照以下步骤重复操作,直到所有正方形都被涂成黑色。

  1. 均匀随机地从盒子中取出一个球。
  2. xx 为该球的索引。将正方形 Lx,Lx+1,,RxL_x, L_x+1, \ldots, R_x 涂成黑色。
  3. 将球放回盒子。

求该过程需要执行次数的期望值,结果对 998244353998244353 取模(参见注释)。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

There are NN squares numbered 11 to NN. Initially, all squares are painted white.

Additionally, there are MM balls numbered 11 to MM in a box.

We repeat the procedure below until all squares are painted black.

  1. Pick up a ball from a box uniformly at random.
  2. Let xx be the index of the ball. Paint Squares Lx,Lx+1,,RxL_x, L_x+1, \ldots, R_x black.
  3. Return the ball to the box.

Find the expected value of the number of times the procedure is done, modulo 998244353998244353 (see Notes).

Notes

It can be proved that the sought expected value is always a rational number. Additionally, under the Constraints of this problem, when that value is represented as PQ\frac{P}{Q} using two coprime integers PP and QQ, it can be proved that there uniquely exists an integer RR such that R×QP(mod998244353)R \times Q \equiv P\pmod{998244353} and 0R<9982443530 \leq R \lt 998244353. You should find this RR.

Constraints

  • 1N,M4001 \leq N,M \leq 400
  • 1LiRiN1 \leq L_i \leq R_i \leq N
  • For every square ii, there is an integer jj such that LjiRjL_j \leq i \leq R_j.
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN MM

L1L_1 R1R_1

L2L_2 R2R_2

\hspace{0.5cm}\vdots

LML_M RMR_M

Output

Print the sought expected value modulo 998244353998244353.

Sample Input 1

3 3
1 1
1 2
2 3

Sample Output 1

499122180

The sought expected value is 72\frac{7}{2}.

We have 499122180×27(mod998244353)499122180 \times 2 \equiv 7\pmod{998244353}, so 499122180499122180 should be printed.

Sample Input 2

13 10
3 5
5 9
3 12
1 13
9 11
12 13
2 4
9 12
9 11
7 11

Sample Output 2

10

Sample Input 3

100 11
22 43
84 93
12 71
49 56
8 11
1 61
13 80
26 83
23 100
80 85
9 89

Sample Output 3

499122193

update @ 2024/3/10 10:26:14