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.
你正在穿过一个矩形场地。该场地可表示为一个 3 行 m 列的矩阵。记 (i,j) 为第 i 行、第 j 列的格子。
你的起点为 (2,1),终点必须为 (2,m)。从格子 (i,j) 出发,你可以移动到以下格子之一:
- (i−1,j+1) —— 仅当 i>1 时允许;
- (i,j+1);
- (i+1,j+1) —— 仅当 i<3 时允许。
然而,路径上有 n 个障碍物阻挡你的通行。第 k 个障碍物由三个整数 ak、lk 和 rk 表示,它禁止进入所有满足 lk≤j≤rk 的格子 (ak,j)。
你需要计算从 (2,1) 到 (2,m) 的不同路径总数,并将结果对 109+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.
第一行包含两个整数 n 和 m(1≤n≤104,3≤m≤1018),分别表示障碍物的数量和矩阵的列数。
接下来有 n 行,每行包含三个整数 ak、lk 和 rk(1≤ak≤3,2≤lk≤rk≤m−1),表示一个障碍物,它阻塞所有满足 lk≤j≤rk 的格子 (ak,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, m) 的不同路径数量,结果对 109 + 7 取模。若无法从 (2, 1) 到达 (2, m),则路径数量为 0。
输入输出样例
输入#1
2 5 1 3 4 2 2 3
输出#1
2
输入解题思路,AI测评打分。不知道怎么写?