luogu#P9126. [USACO23FEB] Moo Route II S

[USACO23FEB] Moo Route II S

题目描述

Note: The time limit for this problem is 4s, twice the default.

Bessie is on vacation! Due to some recent technological advances, Bessie will travel via technologically sophisticated flights, which can even time travel. Furthermore, there are no issues if two "parallel" versions of Bessie ever meet.

In the country there are NN airports numbered 1,2,,N1,2,\cdots ,N and MM time-traveling flights (1N,M200000)(1 \le N,M \le 200000). Flight jj leaves airport cjc_j at time rjr_j, and arrives in airport djd_j at time sj(0rj,sj109s_j (0 \le rj,sj \le 10^9, sj<rjs_j<r_j is possible)). In addition, she must leave aia_i time for a layover at airport i(1ai109)i (1 \le a_i \le 10^9). (That is to say, if Bessie takes a flight arriving in airport ii at time ss, she can then transfer to a flight leaving the airport at time rr if rs+air \ge s+a_i. The layovers do not affect when Bessie arrives at an airport.)

Bessie starts at city 11 at time 00. For each airport from 11 to NN, what is the earliest time when Bessie can get to at it?

输入格式

The first line of input contains NN and MM.

The next MM lines describe flights. The jj-th of these lines contains cj,rj,dj,sjc_j, r_j, d_j, s_j in that order. (1cj,djN,0rj,sj109)(1 \le c_j,d_j \le N, 0 \le r_j,s_j \le 10^9)

The next line describes airports. It contains NN space separated integers, a1,,aNa_1, \cdots ,a_N.

输出格式

There are NN lines of output. Line ii contains the earliest time when Bessie can get to airport ii, or 1-1 if it is not possible for Bessie to get to that airport.

题目大意

题目描述

注意:本题的时间限制为 4 秒,是默认限制的两倍。

Bessie 正在度假!由于最近的技术进步,Bessie 可以通过先进的航班旅行,这些航班甚至可以进行时间旅行。此外,即使存在多个“平行”的 Bessie 同时出现也不会有任何问题。

在这个国家,有 NN 个机场,编号为 1,2,,N1,2,\cdots,N,以及 MM 条时间旅行航班(1N,M2000001 \leq N,M \leq 200000)。第 jj 条航班从机场 cjc_j 在时间 rjr_j 起飞,并在时间 sjs_j 抵达机场 djd_j0rj,sj1090 \leq r_j,s_j \leq 10^9sj<rjs_j < r_j 是可能的)。此外,Bessie 在机场 ii 需要停留 aia_i 时间(1ai1091 \leq a_i \leq 10^9)。也就是说,如果 Bessie 乘坐一趟航班在时间 ss 抵达机场 ii,她可以转乘一趟从该机场出发的航班,只要该航班的起飞时间 rs+air \geq s + a_i。需要注意的是,停留时间不会影响 Bessie 抵达某机场的实际时间。

Bessie 从城市 11 出发,起始时间为 00。对于从 11NN 的每个机场,求出 Bessie 最早可以到达该机场的时间。

输入格式

第一行输入包含两个整数 NNMM

接下来的 MM 行描述航班信息。其中第 jj 行包含 cj,rj,dj,sjc_j, r_j, d_j, s_j,依次表示航班的起飞机场、起飞时间、降落机场和降落时间。(1cj,djN,0rj,sj109)(1 \leq c_j,d_j \leq N, 0 \leq r_j,s_j \leq 10^9)

接下来的 11 行描述每个机场的停留时间。该行包含 NN 个用空格分隔的整数,分别为 a1,,aNa_1,\cdots,a_N

输出格式

输出共 NN 行。第 ii 行输出 Bessie 最早到达机场 ii 的时间;如果无法到达该机场,输出 1-1

样例 1 的解释

Bessie 可以按照给定的顺序乘坐第 33 班航班,这使她可以在时间 00 到达机场 11 和机场 22,以及在时间 2020 到达机场 33

注意,这条路线会两次经过机场 22,第一次是在时间 101110-11,第二次是在时间 010-1

样例 2 的解释

在这个例子中,Bessie 可以乘坐第 11 班航班,在时间 1010 抵达机场 22。但是,她无法及时赶上第 22 班航班,因为该航班的起飞时间为 1010,而她需要至少 11 个时间单位来完成停留。

评分标准

  • 测试点 353-5:对于每个 jjrj<sjr_j < s_j,也就是说所有航班的到达时间晚于起飞时间。
  • 测试点 6106-10N,M5000N,M \leq 5000
  • 测试点 112011-20:无额外限制。
3 3
1 0 2 10
2 11 2 0
2 1 3 20
10 1 10
0
0
20
3 3
1 0 2 10
2 10 2 0
2 1 3 20
10 1 10
0
10
-1

提示

Explanation for Sample 1

Bessie can take the 33 flights in the listed order, which allows her to arrive at airports 11 and 22 at time 00, and airport 33 at time 2020.

Note that this route passes through airport 22 twice, first from time 101110-11 and then from time 010-1.

Explanation for Sample 2

In this case, Bessie can take flight 11, arriving at airport 22 at time 1010. However, she does not arrive in time to also take flight 22, since the departure time is 1010 and she cannot make a 11 time-unit layover.

SCORING

  • Inputs 353-5: rj<sjr_j<s_j for all jj, i.e. all flights arrive after they depart.
  • Inputs 6106-10: N,M5000N,M \le 5000
  • Inputs 112011-20: No additional constraints.