CF1209H.Moving Walkways

NOI/NOI+/CTSC

通过率:0%

时间限制:2.50s

内存限制:256MB

AC君温馨提醒

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

题目描述

Airports often use moving walkways to help you walking big distances faster. Each such walkway has some speed that effectively increases your speed. You can stand on such a walkway and let it move you, or you could also walk and then your effective speed is your walking speed plus walkway's speed.

Limak wants to get from point 00 to point LL on a straight line. There are nn disjoint walkways in between. The ii-th walkway is described by two integers xix_i and yiy_i and a real value sis_i. The ii-th walkway starts at xix_i, ends at yiy_i and has speed sis_i.

Every walkway is located inside the segment [0,L][0, L] and no two walkways have positive intersection. However, they can touch by endpoints.

Limak needs to decide how to distribute his energy. For example, it might make more sense to stand somewhere (or to walk slowly) to then have a lot of energy to walk faster.

Limak's initial energy is 00 and it must never drop below that value. At any moment, he can walk with any speed vv in the interval [0,2][0, 2] and it will cost him vv energy per second, but he continuously recovers energy with speed of 11 energy per second. So, when he walks with speed vv, his energy increases by (1−v)(1-v). Note that negative value would mean losing energy.

In particular, he can walk with speed 11 and this won't change his energy at all, while walking with speed 0.770.77 effectively gives him 0.230.23 energy per second.

Limak can choose his speed arbitrarily (any real value in interval [0,2][0, 2]) at every moment of time (including the moments when he is located on non-integer positions). Everything is continuous (non-discrete).

What is the fastest time Limak can get from 00 to LL?

机场经常使用自动人行道来帮助旅客更快地跨越较长的距离。每条自动人行道具有一定的速度,能有效提升旅客的行进速度。旅客可选择站在人行道上任其带动前行,也可在人行道上行走,此时其有效速度等于自身步行速度加上人行道的速度。

Limak 需要从一条直线上的点 00 出发,到达点 LL。其间分布着 nn 段互不重叠的自动人行道。第 ii 段人行道由两个整数 xix_i、yiy_i 和一个实数 sis_i 描述:该人行道起始于位置 xix_i,终止于位置 yiy_i,运行速度为 sis_i。

所有人行道均完全位于区间 [0,L][0, L] 内,且任意两段人行道的交集长度为零(即不相交);但它们的端点可以恰好相接。

Limak 需要合理分配自身能量。例如,他可能选择在某处静止不动(或缓慢行走),以保留体力,以便之后能更快速地行走。

Limak 的初始能量为 00,且其能量值在任何时候均不得低于 00。在任意时刻,他可以选择任意速度 v∈[0,2]v \in [0, 2] 行走,此时单位时间消耗 vv 单位能量;同时,他持续以每秒 11 单位能量的速度恢复能量。因此,当以速度 vv 行走时,其能量变化速率为 (1−v)(1 - v)(负值表示能量减少)。

特别地,若以速度 11 行走,则能量保持不变;而以速度 0.770.77 行走,则单位时间净增加 0.230.23 单位能量。

Limak 可在任意时刻(包括处于非整数位置的时刻)自由选择任意满足 v∈[0,2]v \in [0, 2] 的实数速度。整个过程是连续的(非离散的)。

问:Limak 从 00 到达 LL 所需的最短时间是多少?

输入格式

The first line contains integers nn and LL (1≤n≤200 0001 \le n \le 200\,000, 1≤L≤1091 \le L \le 10^9), the number of walkways and the distance to walk.

Each of the next nn lines contains integers xix_i, yiy_i and real value sis_i (0≤xi<yi≤L0 \le x_i \lt y_i \le L, 0.1≤si≤10.00.1 \le s_i \le 10.0). The value sis_i is given with at most 99 digits after decimal point.

It's guaranteed, that no two walkways have a positive intersection. The walkways are listed from left to right. That is, yi≤xi+1y_i \le x_{i + 1} for 1≤i≤n−11 \le i \le n - 1.

第一行包含两个整数 nn 和 LL(1≤n≤200 0001 \le n \le 200\,000,1≤L≤1091 \le L \le 10^9),分别表示自动步道的数量和需要行走的总距离。

接下来的 nn 行中,每行包含两个整数 xix_i、yiy_i 和一个实数 sis_i(0≤xi<yi≤L0 \le x_i \lt y_i \le L,0.1≤si≤10.00.1 \le s_i \le 10.0)。其中 sis_i 最多保留小数点后 99 位。

保证任意两条自动步道的交集长度为 00(即不相交或仅在端点处接触)。自动步道按从左到右的顺序给出,即对所有 1≤i≤n−11 \le i \le n - 1,满足 yi≤xi+1y_i \le x_{i + 1}。

输出格式

Print one real value, the fastest possible time to reach LL. Your answer will be considered correct if its absolute or relative error won't exceed 10−910^{-9}.

输出一个实数值,即到达 LL 的最短可能时间。若您的答案的绝对或相对误差不超过 10−910^{-9},则视为正确。

输入输出样例

  • 输入#1

    1 5
    0 2 2.0

    输出#1

    3.000000000000
  • 输入#2

    1 5
    2 4 0.91

    输出#2

    3.808900523560
  • 输入#3

    3 1000
    0 990 1.777777
    995 996 1.123456789
    996 1000 2.0

    输出#3

    361.568848429553

说明/提示

The drawings show the first two examples. In the first one, there is a walkway from 00 to 22 with speed 2.02.0 and Limak wants to get to point 55. The second example has a walkway from 22 to 44 with speed 0.910.91.

In the first example, one of optimal strategies is as follows.

  • Get from 00 to 22 by standing still on the walkway. It moves you with speed 22 so it takes 11 second and you save up 11 energy.
  • Get from 22 to 44 by walking with max speed 22 for next 11 second. It takes 11 second again and the energy drops to 00.
  • Get from 44 to 55 by walking with speed 11. It takes 11 second and the energy stays constant at the value 00.

The total time is 1+1+1=31 + 1 + 1 = 3.

示意图展示了前两个例子。在第一个例子中,有一条从 00 到 22 的自动步道,其速度为 2.02.0,Limak 需要到达位置 55。第二个例子中有一条从 22 到 44 的自动步道,其速度为 0.910.91。

在第一个例子中,一种最优策略如下:

  • 从 00 到 22,静止站在自动步道上。步道以速度 22 带你前进,耗时 11 秒,同时你节省了 11 单位能量。
  • 从 22 到 44,以最大速度 22 行走 11 秒。再次耗时 11 秒,能量降至 00。
  • 从 44 到 55,以速度 11 行走。耗时 11 秒,能量保持为 00 不变。

总时间为 1+1+1=31 + 1 + 1 = 3。

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

首页