QOJ.ac

QOJ

时间限制: 2 s 内存限制: 1024 MB 总分: 100

#10051. 我的缆车

统计

玻利维亚的首都拉巴斯以其旅游景点和名为“Mi Teleférico”的空中缆车而闻名。你现在正在拉巴斯观光,并希望尽可能多地游览观光景点。在本题中,我们考虑以下简化的情况。

拉巴斯有 $N$ 个空中缆车站,按海拔高度升序编号为 $1$ 到 $N$。有 $M$ 条单向线路,编号为 $1$ 到 $M$。有 $P$ 家空中缆车公司,编号为 $1$ 到 $P$。每条线路均由一家公司管理。线路 $i$ ($1 \le i \le M$) 从车站 $A_i$ 运行至车站 $B_i$,并由公司 $C_i$ 管理。在此,线路总是从海拔较低的车站运行至海拔较高的车站。换句话说,$A_i < B_i$ 成立。

拉巴斯交通局为了方便起见,发行了无限次乘车通行证。每张通行证包含两个整数 $l, r$,满足 $1 \le l \le r \le P$。该通行证允许持有人乘坐由公司 $l, l+1, \dots, r$ 中任意一家管理的所有线路。换句话说,对于满足 $1 \le i \le M$ 的整数 $i$,当 $l \le C_i \le r$ 成立时,该通行证允许持有人乘坐线路 $i$。一张通行证可以用于多条线路。我们将这种通行证记为 $(l, r)$。

现在,有 $Q$ 名游客(编号为 $1$ 到 $Q$)访问拉巴斯。游客 $j$ ($1 \le j \le Q$) 持有一张通行证 $(L_j, R_j)$ 和 $X_j$ 玻利维亚诺现金。

每位游客的目标是确保在使用其持有的通行证所能乘坐的线路的情况下,所有车站都能从车站 $1$ 到达。游客 $j$ ($1 \le j \le Q$) 可以通过以下过程交换他/她的通行证以实现目标。每位游客最多只能交换一次。

  1. 他/她选择两个整数 $l', r'$,满足 $1 \le l' \le r' \le P$。
  2. 他/她将通行证 $(L_j, R_j)$ 交换为通行证 $(l', r')$。这需要支付 $|L_j - l'| + |R_j - r'|$ 玻利维亚诺作为费用。

你的任务是确定每位游客是否能在其拥有的现金范围内实现他/她的目标。

编写一个程序,在给定车站、线路和游客信息的情况下,确定每位游客是否能在其拥有的现金范围内实现他/她的目标。

输入格式

从标准输入读取以下数据:

$N \ M \ P$ $A_1 \ B_1 \ C_1$ $A_2 \ B_2 \ C_2$ $\vdots$ $A_M \ B_M \ C_M$ $Q$ $L_1 \ R_1 \ X_1$ $L_2 \ R_2 \ X_2$ $\vdots$ $L_Q \ R_Q \ X_Q$

输出格式

向标准输出写入 $Q$ 行。在第 $j$ 行 ($1 \le j \le Q$),如果游客 $j$ 可以实现他/她的目标,则输出 Yes,否则输出 No。

数据范围

  • $2 \le N \le 300\,000$
  • $1 \le M \le 300\,000$
  • $1 \le P \le 10^9$
  • $1 \le A_i < B_i \le N$ ($1 \le i \le M$)
  • $1 \le C_i \le P$ ($1 \le i \le M$)
  • $1 \le Q \le 400\,000$
  • $1 \le L_j \le R_j \le P$ ($1 \le j \le Q$)
  • $0 \le X_j \le 10^9$ ($1 \le j \le Q$)
  • 给定值均为整数。

子任务

  1. (7 分) $N \le 50, M \le 50, Q \le 50, X_j = 0$ ($1 \le j \le Q$)
  2. (8 分) $P \le 10$
  3. (11 分) $P \le 100$
  4. (23 分) $P \le 300\,000, X_j = 0$ ($1 \le j \le Q$)
  5. (9 分) $P \le 300\,000$
  6. (22 分) $N \le 8\,000, M \le 8\,000$
  7. (20 分) 无附加限制

样例

样例输入 1

4 6 10
1 2 3
2 4 7
1 2 6
2 3 5
3 4 2
3 4 8
4
3 7 0
5 6 0
3 4 0
1 9 0

样例输出 1

Yes
No
No
Yes

样例输入 2

4 6 10
1 2 3
2 4 7
1 2 6
2 3 5
3 4 2
3 4 8
3
5 6 10
3 4 1
7 8 3

样例输出 2

Yes
No
Yes

样例输入 3

3 1 1000000000
1 2 6
1
1 1000000000 1000000000

样例输出 3

No

样例输入 4

5 9 2000
2 3 1814
2 3 457
1 2 1226
3 4 1354
1 5 1050
1 2 1725
2 3 1383
1 5 1626
1 4 1795
5
850 1872 128
82 428 1217
487 924 573
1639 1926 202
202 420 25

样例输出 4

Yes
Yes
Yes
Yes
No

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.