AT_abc466_g.Segment Sum Constraints

NOI/NOI+/CTSC

通过率:0%

时间限制:2.00s

内存限制:1024MB

AC君温馨提醒

该题目为【atcoder】题库的题目,您提交的代码将被提交至atcoder进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given MM triples of integers (Li,Ri,Si)(L_i,R_i,S_i).
Consider tuples A=(A1,A2,…,AN)A=(A_1,A_2,\ldots,A_N) of NN positive integers satisfying all of the following conditions.

  • The sum of ALi,ALi+1,…,ARiA_{L_i}, A_{L_i+1}, \ldots, A_{R_i} is SiS_i.

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

给你 MM 个整数三元组 (Li,Ri,Si)(L_i,R_i,S_i)。
考虑由 NN 个正整数构成的元组 A=(A1,A2,…,AN)A=(A_1,A_2,\ldots,A_N),要求其满足以下所有条件:

  • ALi+ALi+1+⋯+ARi=SiA_{L_i} + A_{L_i+1} + \cdots + A_{R_i} = S_i。

若满足条件的元组有无穷多个,则输出 Infinity;否则,输出满足条件的元组个数对 998244353998244353 取模的结果。

输入格式

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

NN MM
L1L_1 R1R_1 S1S_1
L2L_2 R2R_2 S2S_2
⋮\vdots
LML_M RMR_M SMS_M

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

NN MM
L1L_1 R1R_1 S1S_1
L2L_2 R2R_2 S2S_2
⋮\vdots
LML_M RMR_M SMS_M

输出格式

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

如果满足条件的元组有无穷多个,则输出 Infinity;否则,输出满足条件的元组个数对 998244353998244353 取模的结果。

输入输出样例

  • 输入#1

    3 2
    1 2 7
    2 3 10

    输出#1

    6
  • 输入#2

    2 1
    1 1 10

    输出#2

    Infinity
  • 输入#3

    2 2
    1 1 10
    1 2 1

    输出#3

    0

说明/提示

Sample 1 Explanation:
We have the following two conditions.

  • A1+A2=7A_1+A_2=7
  • A2+A3=10A_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)A=(1,6,4), (2,5,5), (3,4,6), (4,3,7), (5,2,8), (6,1,9) satisfy the conditions, so output 66 modulo 998244353998244353, that is, output 66.

Sample 2 Explanation:
There are infinitely many tuples AA satisfying the conditions.

Sample 3 Explanation:
There is no tuple AA satisfying the conditions.

Constraints

  • 1≤N≤81 \leq N \leq 8
  • 1≤M≤361 \leq M \leq 36
  • 1≤Li≤Ri≤N1\leq L_i\leq R_i\leq N
  • 1≤Si≤1091\leq S_i\leq 10^9
  • All (Li,Ri)(L_i,R_i) are distinct.
  • All input values are integers.

样例 1 解释:
我们有以下两个条件:

  • A1+A2=7A_1+A_2=7
  • A2+A3=10A_2+A_3=10

满足条件的六元组 A=(1,6,4),(2,5,5),(3,4,6),(4,3,7),(5,2,8),(6,1,9)A=(1,6,4), (2,5,5), (3,4,6), (4,3,7), (5,2,8), (6,1,9) 共有 6 个,因此输出 66 对 998244353998244353 取模的结果,即输出 66。

样例 2 解释:
满足条件的元组 AA 有无穷多个。

样例 3 解释:
不存在满足条件的元组 AA。

约束条件

  • 1≤N≤81 \leq N \leq 8
  • 1≤M≤361 \leq M \leq 36
  • 1≤Li≤Ri≤N1\leq L_i\leq R_i\leq N
  • 1≤Si≤1091\leq S_i\leq 10^9
  • 所有 (Li,Ri)(L_i,R_i) 互不相同。
  • 所有输入值均为整数。

输入解题思路,AI测评打分。不知道怎么写?

首页