102427: [AtCoder]ABC242 Ex - Random Painting

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Score : $600$ points

Problem Statement

There are $N$ squares numbered $1$ to $N$. Initially, all squares are painted white.

Additionally, there are $M$ balls numbered $1$ to $M$ 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 $x$ be the index of the ball. Paint Squares $L_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 $998244353$ (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 $\frac{P}{Q}$ using two coprime integers $P$ and $Q$, it can be proved that there uniquely exists an integer $R$ such that $R \times Q \equiv P\pmod{998244353}$ and $0 \leq R \lt 998244353$. You should find this $R$.

Constraints

  • $1 \leq N,M \leq 400$
  • $1 \leq L_i \leq R_i \leq N$
  • For every square $i$, there is an integer $j$ such that $L_j \leq i \leq R_j$.
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

$N$ $M$
$L_1$ $R_1$
$L_2$ $R_2$
$\hspace{0.5cm}\vdots$
$L_M$ $R_M$

Output

Print the sought expected value modulo $998244353$.


Sample Input 1

3 3
1 1
1 2
2 3

Sample Output 1

499122180

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

We have $499122180 \times 2 \equiv 7\pmod{998244353}$, so $499122180$ 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

Input

题意翻译

有 $m$ 个小球,一开始标号为 $1\sim m$,每个对应一个区间 $[L_i,R_i]$。有 $n$ 个方块,标号 $1\sim n$,初始时无色。重复以下步骤直到所有的方块都被涂色: 1. 随机拿出一个小球 $i$ 2. 将 $[L_i,R_i]$ 涂色 3. 将小球放回去 问期望进行步骤的次数。 - $1\le n,m\le 400,1\le L_i,R_i\le n$

Output

得分:600分 部分 问题描述 有编号为1到N的N个方格。最初,所有的方格都被涂成白色。 此外,盒子里有编号为1到M的M个球。 我们重复以下过程,直到所有方格都被涂成黑色。 1. 从盒子里随机取出一个球。 2. 让x为球的编号。将方格L_x, L_x+1, ..., R_x涂成黑色。 3. 将球放回盒子里。 求该过程重复的次数的期望值,取模998244353(参见注释)。 部分 注释 可以证明所求期望值始终为有理数。此外,在本问题的约束下,当该值表示为$\frac{P}{Q}$时,可以证明存在唯一的整数R,使得$R \times Q \equiv P\pmod{998244353}$且$0 \leq R \lt 998244353$。你应该找到这个R。 部分 约束 * $1 \leq N,M \leq 400$ * $1 \leq L_i \leq R_i \leq N$ * 对于每个方格i,都存在一个整数j,使得$L_j \leq i \leq R_j$。 * 输入中的所有值都是整数。 部分 输入 输入格式如下: $N$ $M$ $L_1$ $R_1$ $L_2$ $R_2$ $\hspace{0.5cm}\vdots$ $L_M$ $R_M$ 部分 输出 输出所求期望值对998244353取模的结果。 部分 样例输入1 3 3 1 1 1 2 2 3 部分 样例输出1 499122180 所求期望值为$\frac{7}{2}$。 我们有$499122180 \times 2 \equiv 7\pmod{998244353}$,因此应输出499122180。 部分 样例输入2 13 10 3 5 5 9 3 12 1 13 9 11 12 13 2 4 9 12 9 11 7 11 部分 样例输出2 10 部分 样例输入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

加入题单

算法标签: