102627: [AtCoder]ABC262 Ex - Max Limited Sequence

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

Description

Score : $600$ points

Problem Statement

Find the number, modulo $998244353$, of integer sequences $A = (A_1, \dots, A_N)$ of length $N$ that satisfy all of the following conditions:

  • $0 \leq A_i \leq M$ for all $i$ such that $1 \leq i \leq N$.
  • The maximum value of $A_{L_j}, \dots, A_{R_j}$ is $X_j$ for all $j$ such that $1 \leq j \leq Q$.

Constraints

  • $1 \leq N \leq 2 \times 10^5$
  • $1 \leq M \lt 998244353$
  • $1 \leq Q \leq 2 \times 10^5$
  • $1 \leq L_i \leq R_i \leq N \, (1 \leq i \leq Q)$
  • $1 \leq X_i \leq M \, (1 \leq i \leq Q)$
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

$N$ $M$ $Q$
$L_1$ $R_1$ $X_1$
$\vdots$
$L_Q$ $R_Q$ $X_Q$

Output

Print the answer.


Sample Input 1

3 3 2
1 2 2
2 3 3

Sample Output 1

5

$A = (0, 2, 3), (1, 2, 3), (2, 0, 3), (2, 1, 3), (2, 2, 3)$ satisfy the conditions.


Sample Input 2

1 1 1
1 1 1

Sample Output 2

1

Sample Input 3

6 40000000 3
1 4 30000000
2 6 20000000
3 5 10000000

Sample Output 3

135282163

Input

题意翻译

### 题目大意 求满足以下条件的长度为 $N$ 的序列 $A=(A_1,A_2,\cdots A_N)$ 有多少种: + $\forall i \in[1,N],0\leq A_i\leq M$ + $\forall i \in[1,Q],\max \limits_{L_i\leq j\leq R_i}A_j=X_i$ ### 输入格式 第一行输入 $3$ 个正整数 $N,M,Q$ 后面 $Q$ 行每行 $3$ 个正整数表示 $L_i,R_i,X_i$ $1\leq N\leq 2\times 10^5$ $1\leq M<998244353$ $1\leq Q\leq 2\times 10^5$ $\forall i \in [1,Q],1\leq L_i\leq R_i\leq N,1\leq X_i\leq M$ ### 输出格式 输出满足条件的序列数,对 $998244353$ 取模。

Output

分数:$600$ 分

问题描述

找到满足以下所有条件的整数序列$A = (A_1, \dots, A_N)$的个数(对$998244353$取模):

  • 对于所有满足$1 \leq i \leq N$的$i$,$0 \leq A_i \leq M$。
  • 对于所有满足$1 \leq j \leq Q$的$j$,$A_{L_j}, \dots, A_{R_j}$的最大值为$X_j$。

约束条件

  • $1 \leq N \leq 2 \times 10^5$
  • $1 \leq M \lt 998244353$
  • $1 \leq Q \leq 2 \times 10^5$
  • $1 \leq L_i \leq R_i \leq N \, (1 \leq i \leq Q)$
  • $1 \leq X_i \leq M \, (1 \leq i \leq Q)$
  • 输入中的所有值都是整数。

输入

输入将从标准输入中按照以下格式给出:

$N$ $M$ $Q$
$L_1$ $R_1$ $X_1$
$\vdots$
$L_Q$ $R_Q$ $X_Q$

输出

打印答案。


样例输入1

3 3 2
1 2 2
2 3 3

样例输出1

5

满足条件的$A$为$(0, 2, 3), (1, 2, 3), (2, 0, 3), (2, 1, 3), (2, 2, 3)$。


样例输入2

1 1 1
1 1 1

样例输出2

1

样例输入3

6 40000000 3
1 4 30000000
2 6 20000000
3 5 10000000

样例输出3

135282163

加入题单

算法标签: