第三回日本最強プログラマー学生選手権-予選-(AtCoder Beginner Contest 262)
Ex
Max Limited Sequence
AtCoder
⌀ 2957
原题
←G →
翻译中…

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.

翻译中…

样例

Input #1
3 3 2
1 2 2
2 3 3
Output #1
5
$A = (0, 2, 3), (1, 2, 3), (2, 0, 3), (2, 1, 3), (2, 2, 3)$ satisfy the conditions.
Input #2
1 1 1
1 1 1
Output #2
1
Input #3
6 40000000 3
1 4 30000000
2 6 20000000
3 5 10000000
Output #3
135282163
题目信息

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