AtCoder Beginner Contest 466
G
区间和约束
Segment Sum Constraints
AtCoder
⌀ 3347
原题
← F→

区间和约束AI (CI翻译)

Problem Statement

题目描述

AI (CI翻译)

You are given $M$ triples of integers $(L_i,R_i,S_i)$. Consider tuples $A=(A_1,A_2,\ldots,A_N)$ of $N$ positive integers satisfying all of the following conditions.

给定 $M$ 个整数三元组 $(L_i,R_i,S_i)$。 考虑由 $N$ 个正整数组成的元组 $A=(A_1,A_2,\ldots,A_N)$,并满足以下所有条件。AI (CI翻译)

  • The sum of $A_{L_i}, A_{L_i+1}, \ldots, A_{R_i}$ is $S_i$.
  • $A_{L_i}, A_{L_i+1}, \ldots, A_{R_i}$ 的和为 $S_i$。
AI (CI翻译)

If there are infinitely many tuples satisfying the conditions, output Infinity; otherwise, output the number of such tuples, modulo $998244353$.

如果满足条件的元组有无限多个,输出 Infinity;否则,输出满足条件的元组数量对 $998244353$ 取模后的结果。AI (CI翻译)

Constraints

约束条件

AI (CI翻译)
  • $1 \leq N \leq 8$
  • $1 \leq M \leq 36$
  • $1\leq L_i\leq R_i\leq N$
  • $1\leq S_i\leq 10^9$
  • All $(L_i,R_i)$ are distinct.
  • All input values are integers.
  • $1 \leq N \leq 8$
  • $1 \leq M \leq 36$
  • $1\leq L_i\leq R_i\leq N$
  • $1\leq S_i\leq 10^9$
  • 所有 $(L_i,R_i)$ 均不相同。
  • 所有输入值均为整数。
AI (CI翻译)

Input

输入格式

AI (CI翻译)

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

输入从标准输入按以下格式给出:AI (CI翻译)

N M
L_1 R_1 S_1
L_2 R_2 S_2
\vdots
L_M R_M S_M

N M
L_1 R_1 S_1
L_2 R_2 S_2
\vdots
L_M R_M S_M
AI (CI翻译)

Output

输出格式

AI (CI翻译)

If there are infinitely many tuples satisfying the conditions, output Infinity; otherwise, output the number of such tuples, modulo $998244353$.

如果满足条件的元组有无限多个,输出 Infinity;否则,输出满足条件的元组数量对 $998244353$ 取模后的结果。AI (CI翻译)

样例

Input #1
3 2
1 2 7
2 3 10
Output #1
6
We have the following two conditions. - $A_1+A_2=7$ - $A_2+A_3=10$ The six tuples $A=(1,6,4), (2,5,5), (3,4,6), (4,3,7), (5,2,8), (6,1,9)$ satisfy the conditions, so output $6$ modulo $998244353$, that is, output $6$.
Input #2
2 1
1 1 10
Output #2
Infinity
There are infinitely many tuples $A$ satisfying the conditions.
Input #3
2 2
1 1 10
1 2 1
Output #3
0
There is no tuple $A$ satisfying the conditions.
题目信息
题号
abc466_g
时间限制
2 s
内存限制
1024 MB

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