Domino Arrangement

AtCoder
IDabc435_g
Time2000ms
Memory256MB
Difficulty
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$ [samples]
Samples
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:
![image](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$.
API Response (JSON)
{
  "problem": {
    "name": "Domino Arrangement",
    "description": {
      "content": "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 ",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "abc435_g"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "There are $N$ cells numbered from $1$ to $N$. Initially, no cell is painted with any color.\nThere are $M$ types of colors, and with the $i$\\-th color, you can paint any number of cells you like among ...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments