AtCoder Beginner Contest 435
G
Domino Arrangement
AtCoder
⌀ 2519
原题
翻译中…

Problem Statement

翻译中…

There are $N$ cells numbered from $1$ to $N$. Initially, no cell is painted with any color.

翻译中…

There are $M$ types of colors, and with the $i$-th color, you can paint any number of cells you like among cells $L_i,L_i+1,\ldots,R_i$.

翻译中…

Find the number, modulo $998244353$, of ways to paint the cells that satisfy the following condition:

翻译中…
  • For every cell $i$, if that cell is painted with a color, then exactly one of cells $i-1$ and $i+1$ is painted with the same color as cell $i$.
  • Here, cells $0$ and $N+1$ are considered to be not painted with any color.
翻译中…

Constraints

翻译中…
  • $1\leq N,M \leq 5\times 10^5$
  • $1\leq L_i \leq R_i \leq N$
  • All input values are integers.
翻译中…

Input

翻译中…

The input is given from Standard Input in the following format:

翻译中…

N M
L_1 R_1
\vdots
L_M R_M

翻译中…

Output

翻译中…

Output the answer.

翻译中…

样例

Input #1
5 2
1 3
1 5
Output #1
11
The first color can paint cells $1,2,3$, and the second color can paint cells $1,2,3,4,5$. There are $11$ ways to paint that satisfy the condition, as follows: ![Figure](https://img.atcoder.jp/abc435/03fd1b0a01e7b5e51ebb60b7b4f1a610.png)
Input #2
3 3
1 1
2 2
3 3
Output #2
1
The one way of not painting any cell satisfies the condition.
Input #3
500000 10
1 499999
2 499998
3 499997
4 499996
5 499995
6 499994
7 499993
8 499992
9 499991
10 499990
Output #3
775503999
Find the count modulo $998244353$.
题目信息
题号
abc435_g
时间限制
2 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。