CF1039A.Timetable

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:512MB

AC君温馨提醒

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

题目描述

There are two bus stops denoted A and B, and there nn buses that go from A to B every day. The shortest path from A to B takes tt units of time but some buses might take longer paths. Moreover, buses are allowed to overtake each other during the route.

At each station one can find a sorted list of moments of time when a bus is at this station. We denote this list as a1<a2<…<ana_1 \lt a_2 \lt \ldots \lt a_n for stop A and as b1<b2<…<bnb_1 \lt b_2 \lt \ldots \lt b_n for stop B. The buses always depart from A and arrive to B according to the timetable, but the order in which the buses arrive may differ. Let's call an order of arrivals valid if each bus arrives at least tt units of time later than departs.

It is known that for an order to be valid the latest possible arrival for the bus that departs at aia_i is bxib_{x_i}, i.e. xix_i-th in the timetable. In other words, for each ii there exists such a valid order of arrivals that the bus departed ii-th arrives xix_i-th (and all other buses can arrive arbitrary), but there is no valid order of arrivals in which the ii-th departed bus arrives (xi+1)(x_i + 1)-th.

Formally, let's call a permutation p1,p2,…,pnp_1, p_2, \ldots, p_n valid, if bpi≥ai+tb_{p_i} \ge a_i + t for all ii. Then xix_i is the maximum value of pip_i among all valid permutations.

You are given the sequences a1,a2,…,ana_1, a_2, \ldots, a_n and x1,x2,…,xnx_1, x_2, \ldots, x_n, but not the arrival timetable. Find out any suitable timetable for stop B b1,b2,…,bnb_1, b_2, \ldots, b_n or determine that there is no such timetable.

有两个公交站,分别记为 A 和 B,每天有 nn 辆公交车从 A 开往 B。从 A 到 B 的最短路径耗时 tt 个单位时间,但某些公交车可能选择更长的路径。此外,公交车在行驶途中允许相互超车。

在每个车站,均可查到一份按时间顺序排列的公交车到站时刻列表。我们将该列表在 A 站记为 a1<a2<…<ana_1 \lt a_2 \lt \ldots \lt a_n,在 B 站记为 b1<b2<…<bnb_1 \lt b_2 \lt \ldots \lt b_n。公交车始终严格依照时刻表从 A 出发、在 B 到达,但到达 B 的顺序可能与出发顺序不同。我们称一个到达顺序是有效的,当且仅当每辆公交车的到达时刻至少比其出发时刻晚 tt 个单位时间。

已知:对于每个 ii,若某辆公交车在 A 站第 ii 个出发(即出发时刻为 aia_i),则其在 B 站最晚可能的到达位置(即在 B 站时刻表 b1,b2,…,bnb_1, b_2, \ldots, b_n 中的序号)为 bxib_{x_i}。换言之,对每个 ii,存在某个有效的到达顺序,使得第 ii 个出发的公交车恰好是第 xix_i 个到达的(其余公交车的到达次序可任意);但不存在任何有效的到达顺序,使得第 ii 个出发的公交车是第 (xi+1)(x_i + 1) 个到达的。

形式化地,称一个排列 p1,p2,…,pnp_1, p_2, \ldots, p_n 是有效的,当且仅当对所有 ii 均满足 bpi≥ai+tb_{p_i} \ge a_i + t。那么 xix_i 即为所有有效排列中 pip_i 的最大可能取值。

现给定序列 a1,a2,…,ana_1, a_2, \ldots, a_n 和 x1,x2,…,xnx_1, x_2, \ldots, x_n,但未给出 B 站的到达时刻表。请构造出任意一组满足条件的 B 站时刻表 b1,b2,…,bnb_1, b_2, \ldots, b_n,或判定不存在这样的时刻表。

输入格式

The first line of the input contains two integers nn and tt (1≤n≤200 0001 \leq n \leq 200\,000, 1≤t≤10181 \leq t \leq 10^{18}) — the number of buses in timetable for and the minimum possible travel time from stop A to stop B.

The second line contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (1≤a1<a2<…<an≤10181 \leq a_1 \lt a_2 \lt \ldots \lt a_n \leq 10^{18}), defining the moments of time when the buses leave stop A.

The third line contains nn integers x1,x2,…,xnx_1, x_2, \ldots, x_n (1≤xi≤n1 \leq x_i \leq n), the ii-th of them stands for the maximum possible timetable position, at which the ii-th bus leaving stop A can arrive at stop B.

输入的第一行包含两个整数 nn 和 tt(1≤n≤200 0001 \leq n \leq 200\,000,1≤t≤10181 \leq t \leq 10^{18})——分别表示时刻表中公交车的数量,以及从站点 A 到站点 B 的最小可能旅行时间。

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(1≤a1<a2<…<an≤10181 \leq a_1 \lt a_2 \lt \ldots \lt a_n \leq 10^{18}),表示各辆公交车离开站点 A 的时刻。

第三行包含 nn 个整数 x1,x2,…,xnx_1, x_2, \ldots, x_n(1≤xi≤n1 \leq x_i \leq n),其中第 ii 个数表示:第 ii 辆从站点 A 出发的公交车,最迟可于时刻表中的第 xix_i 个位置到达站点 B。

输出格式

If a solution exists, print "Yes" (without quotes) in the first line of the output.

In the second line print nn integers b1,b2,…,bnb_1, b_2, \ldots, b_n (1≤b1<b2<…<bn≤3⋅10181 \leq b_1 \lt b_2 \lt \ldots \lt b_n \leq 3 \cdot 10^{18}). We can show that if there exists any solution, there exists a solution that satisfies such constraints on bib_i. If there are multiple valid answers you can print any of them.

If there is no valid timetable, print "No" (without quotes) in the only line of the output.

如果存在解,则在输出的第一行打印“Yes”(不带引号)。

在第二行打印 nn 个整数 b1,b2,…,bnb_1, b_2, \ldots, b_n(满足 1≤b1<b2<…<bn≤3⋅10181 \leq b_1 \lt b_2 \lt \ldots \lt b_n \leq 3 \cdot 10^{18})。我们可以证明:若存在任意解,则必存在一个满足上述关于 bib_i 的约束条件的解。若存在多个合法答案,可输出其中任意一个。

若不存在合法的时间表,则在输出的唯一一行中打印“No”(不带引号)。

输入输出样例

  • 输入#1

    3 10
    4 6 8
    2 2 3

    输出#1

    Yes
    16 17 21
  • 输入#2

    2 1
    1 2
    2 1

    输出#2

    No

说明/提示

Consider the first example and the timetable b1,b2,…,bnb_1, b_2, \ldots, b_n from the output.

To get x1=2x_1 = 2 the buses can arrive in the order (2,1,3)(2, 1, 3). To get x2=2x_2 = 2 and x3=3x_3 = 3 the buses can arrive in the order (1,2,3)(1, 2, 3). x1x_1 is not 33, because the permutations (3,1,2)(3, 1, 2) and (3,2,1)(3, 2, 1) (all in which the 11-st bus arrives 33-rd) are not valid (sube buses arrive too early), x2x_2 is not 33 because of similar reasons.

考虑第一个样例以及输出中的时刻表 b1,b2,…,bnb_1, b_2, \ldots, b_n。

为使 x1=2x_1 = 2,公交车到达顺序可以是 (2,1,3)(2, 1, 3);为使 x2=2x_2 = 2 且 x3=3x_3 = 3,公交车到达顺序可以是 (1,2,3)(1, 2, 3)。x1x_1 不可能是 33,因为排列 (3,1,2)(3, 1, 2) 和 (3,2,1)(3, 2, 1)(即第 11 辆公交车第 33 个到达的所有情况)均不合法(某些公交车到达过早);同理,x2x_2 也不可能是 33。

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

首页