QOJ.ac

QOJ

実行時間制限: 2 s メモリ制限: 128 MB 満点: 100

#9013. 像素鸟

統計

自从 Byteasar 在他的智能手机上安装了游戏《Flappy Bird》后,他就沉迷其中无法自拔。他已经成为了一名狂热的玩家,甚至连最难的关卡对他来说也毫无挑战。因此,为了保持游戏的趣味性,Byteasar 决定以最少的努力通关每一关。秉持着这一理念,他请求你编写一个程序来帮助他实现这一目标。

为了说明他的需求,Byteasar 将游戏过程形式化如下:在任何时刻,由玩家控制的鸟儿可以位于二维笛卡尔坐标系中的任意整点坐标上。初始时,鸟儿位于原点 $(0, 0)$,如果玩家能将鸟儿移动到横坐标为 $X$ 的任意点,即视为获胜。

鸟儿每秒移动一次:如果它当前位于点 $(x, y)$,那么在下一秒它将移动到两个可能点中的一个。具体来说,如果玩家点击屏幕,鸟儿将移动到点 $(x + 1, y + 1)$;如果玩家什么都不做,鸟儿将移动到点 $(x + 1, y - 1)$。

此外,游戏中有 $n$ 个障碍物需要避开。每个障碍物由两条禁行射线组成。如果鸟儿触碰到任何一条禁行射线,玩家立即失败。第 $i$ 个障碍物由三个数字 $(x_i, a_i, b_i)$ 描述,表示在横坐标 $x_i$ 处,纵坐标 $y \le a_i$ 的点以及纵坐标 $y \ge b_i$ 的点构成了该障碍物的禁行射线(如下图所示,表现为细长的矩形)。

给定一组障碍物,Byteasar 想知道获胜所需的最少点击屏幕次数。

输入格式

第一行包含两个整数 $n$ 和 $X$ ($0 \le n \le 500\,000$; $1 \le X \le 10^9$),分别表示障碍物的数量和终点横坐标。接下来的 $n$ 行描述障碍物:第 $i$ 行包含三个整数 $x_i, a_i, b_i$ ($0 < x_i < X$; $a_i < b_i$; $a_i, b_i \in [-10^9, 10^9]$),按照上述格式描述第 $i$ 个障碍物。障碍物按从左到右的顺序排列,即 $x_1 < x_2 < \dots < x_n$。

输出格式

如果对于给定的障碍物集合无法获胜,则在标准输出的第一行(也是唯一一行)打印单词 NIE(波兰语中的“不”)。否则,打印一个非负整数,表示获胜所需的最少点击屏幕次数。

样例

样例输入 1

4 11
4 1 4
7 -1 2
8 -1 3
9 0 2

样例输出 1

5

样例输入 2

1 2
1 -1 1

样例输出 2

NIE

说明

该图描绘了第一个样例测试。箭头标记了玩家应该点击手机屏幕的位置。

子任务

测试集由以下子任务组成。在每个子任务中,可能包含多个测试组。每个子任务均符合“输入格式”部分中指定的规则。

子任务 属性 分值
1 $n \le 1000, X \le 1000, a_i, b_i \in [-1000, 1000]$ 28
2 $n \le 1000, a_i, b_i \in [-1000, 1000]$ 23
3 $b_i = 10^9$ 21
4 无附加属性 28

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.