CF954F.Runner's Problem

提高+/省选-

通过率:0%

时间限制:4.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are running through a rectangular field. This field can be represented as a matrix with 3 rows and m columns. (i, j) denotes a cell belonging to i-th row and j-th column.

You start in (2, 1) and have to end your path in (2, m). From the cell (i, j) you may advance to:

  • (i - 1, j + 1) — only if i > 1,
  • (i, j + 1), or
  • (i + 1, j + 1) — only if i < 3.

However, there are n obstacles blocking your path. k-th obstacle is denoted by three integers a__k, l__k and r__k, and it forbids entering any cell (a__k, j) such that l__k ≤ j ≤ r__k.

You have to calculate the number of different paths from (2, 1) to (2, m), and print it modulo 109 + 7.

你正在穿过一个矩形场地。该场地可表示为一个 33 行 mm 列的矩阵。记 (i, j)(i,\,j) 为第 ii 行、第 jj 列的格子。

你的起点为 (2, 1)(2,\,1),终点必须为 (2, m)(2,\,m)。从格子 (i, j)(i,\,j) 出发,你可以移动到以下格子之一:

  • (i−1, j+1)(i-1,\,j+1) —— 仅当 i>1i > 1 时允许;
  • (i, j+1)(i,\,j+1);
  • (i+1, j+1)(i+1,\,j+1) —— 仅当 i<3i < 3 时允许。

然而,路径上有 nn 个障碍物阻挡你的通行。第 kk 个障碍物由三个整数 aka_k、lkl_k 和 rkr_k 表示,它禁止进入所有满足 lk≤j≤rkl_k \le j \le r_k 的格子 (ak, j)(a_k,\,j)。

你需要计算从 (2, 1)(2,\,1) 到 (2, m)(2,\,m) 的不同路径总数,并将结果对 109+710^9 + 7 取模后输出。

输入格式

The first line contains two integers n and m (1 ≤ n ≤ 104, 3 ≤ m ≤ 1018) — the number of obstacles and the number of columns in the matrix, respectively.

Then n lines follow, each containing three integers a__k, l__k and r__k (1 ≤ a__k ≤ 3, 2 ≤ l__k ≤ r__k ≤ m - 1) denoting an obstacle blocking every cell (a__k, j) such that l__k ≤ j ≤ r__k. Some cells may be blocked by multiple obstacles.

第一行包含两个整数 nn 和 mm(1≤n≤1041 \leq n \leq 10^4,3≤m≤10183 \leq m \leq 10^{18}),分别表示障碍物的数量和矩阵的列数。

接下来有 nn 行,每行包含三个整数 aka_k、lkl_k 和 rkr_k(1≤ak≤31 \leq a_k \leq 3,2≤lk≤rk≤m−12 \leq l_k \leq r_k \leq m-1),表示一个障碍物,它阻塞所有满足 lk≤j≤rkl_k \leq j \leq r_k 的格子 (ak, j)(a_k,\,j)。某些格子可能被多个障碍物同时阻塞。

输出格式

Print the number of different paths from (2, 1) to (2, m), taken modulo 109 + 7. If it is impossible to get from (2, 1) to (2, m), then the number of paths is 0.

输出从点 (2, 1)(2, 1) 到点 (2, m)(2, m) 的不同路径数量,结果对 109 + 710^9 + 7 取模。若无法从 (2, 1)(2, 1) 到达 (2, m)(2, m),则路径数量为 00。

输入输出样例

  • 输入#1

    2 5
    1 3 4
    2 2 3

    输出#1

    2

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

首页