問題一覧 > 通常問題

No.2605 Pickup Parentheses

レベル : / AI推定難易度 : 2250 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (解説公開後に AC するまで非表示) / 解いたユーザー数 44
作問者 : 👑 amentorimaru / テスター : 👑 seekworser
お気に入りにしたユーザー ProblemId : 10283 / 自分の提出
問題文最終更新日: 2024-01-08 13:25:52
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 414 (順位表) の他の問題:

Problem Statement

In a certain virtual space, you can pick up and hold all sorts of things, so it may well be that you can hold a balanced parenthesis sequence too.


A string constructed by any of the following rules is called a balanced parenthesis sequence.

  • The empty string
  • A string obtained by concatenating ( $A$ ) in this order, for some balanced parenthesis sequence $A$
  • A string obtained by concatenating $AB$ in this order, for some balanced parenthesis sequences $A,B$

Etowanyu is about to create a balanced parenthesis sequence, but he has noticed that $M$ users are each likely to pick up the parenthesis sequence from the $L_i$-th character to the $R_i$-th character. Here, it is guaranteed that the intervals $[L_i,R_i]$ do not intersect one another.

Find the number of parenthesis sequences satisfying the following conditions, modulo $998244353$.

  • It is a balanced parenthesis sequence of length $N$.
  • For all $i=1,\dots ,M$, the part from the $L_i$-th character to the $R_i$-th character is not a balanced parenthesis sequence.

Input

$N \ M$
$L_1 \ R_1$
$L_2 \ R_2$
$\vdots$
$L_M \ R_M$

  • All inputs are integers.
  • $1 \le N \le 2\times 10^5$
  • $0 \le M \le N$
  • $1 \le L_1 \le R_1 < L_2 \le R_2 < \dots < L_M \le R_M \le N$

Output

Output the answer.

Sample

Sample 1
Input
6 1
3 4
Output
3

The parenthesis sequences that can be created are the following 3: (()()),(())(),()(()).

((())) and ()()() are also balanced parenthesis sequences as whole strings, but the two characters from the $L_1=3$-rd character to the $R_1=4$-th form (), a balanced parenthesis sequence, so they do not satisfy the condition.

In ((((((, the part from the $3$-rd character to the $4$-th character is not a balanced parenthesis sequence, but the whole string is not a balanced parenthesis sequence.

Sample 2
Input
100 1
1 100
Output
0

There may be cases where no string can be completed.

Sample 3
Input
100 10
7 8
27 34
35 40
51 52
58 59
61 70
75 84
85 86
87 90
95 98
Output
995943820

Find the answer modulo $998244353$.

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。