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 0 to point L on a straight line. There are n disjoint walkways in between. The i-th walkway is described by two integers xi and yi and a real value si. The i-th walkway starts at xi, ends at yi and has speed si.
Every walkway is located inside the segment [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 0 and it must never drop below that value. At any moment, he can walk with any speed v in the interval [0,2] and it will cost him v energy per second, but he continuously recovers energy with speed of 1 energy per second. So, when he walks with speed v, his energy increases by (1−v). Note that negative value would mean losing energy.
In particular, he can walk with speed 1 and this won't change his energy at all, while walking with speed 0.77 effectively gives him 0.23 energy per second.
Limak can choose his speed arbitrarily (any real value in interval [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 0 to L?
机场经常使用自动人行道来帮助旅客更快地跨越较长的距离。每条自动人行道具有一定的速度,能有效提升旅客的行进速度。旅客可选择站在人行道上任其带动前行,也可在人行道上行走,此时其有效速度等于自身步行速度加上人行道的速度。
Limak 需要从一条直线上的点 0 出发,到达点 L。其间分布着 n 段互不重叠的自动人行道。第 i 段人行道由两个整数 xi、yi 和一个实数 si 描述:该人行道起始于位置 xi,终止于位置 yi,运行速度为 si。
所有人行道均完全位于区间 [0,L] 内,且任意两段人行道的交集长度为零(即不相交);但它们的端点可以恰好相接。
Limak 需要合理分配自身能量。例如,他可能选择在某处静止不动(或缓慢行走),以保留体力,以便之后能更快速地行走。
Limak 的初始能量为 0,且其能量值在任何时候均不得低于 0。在任意时刻,他可以选择任意速度 v∈[0,2] 行走,此时单位时间消耗 v 单位能量;同时,他持续以每秒 1 单位能量的速度恢复能量。因此,当以速度 v 行走时,其能量变化速率为 (1−v)(负值表示能量减少)。
特别地,若以速度 1 行走,则能量保持不变;而以速度 0.77 行走,则单位时间净增加 0.23 单位能量。
Limak 可在任意时刻(包括处于非整数位置的时刻)自由选择任意满足 v∈[0,2] 的实数速度。整个过程是连续的(非离散的)。
问:Limak 从 0 到达 L 所需的最短时间是多少?
输入格式
The first line contains integers n and L (1≤n≤200000, 1≤L≤109), the number of walkways and the distance to walk.
Each of the next n lines contains integers xi, yi and real value si (0≤xi<yi≤L, 0.1≤si≤10.0). The value si is given with at most 9 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+1 for 1≤i≤n−1.
第一行包含两个整数 n 和 L(1≤n≤200000,1≤L≤109),分别表示自动步道的数量和需要行走的总距离。
接下来的 n 行中,每行包含两个整数 xi、yi 和一个实数 si(0≤xi<yi≤L,0.1≤si≤10.0)。其中 si 最多保留小数点后 9 位。
保证任意两条自动步道的交集长度为 0(即不相交或仅在端点处接触)。自动步道按从左到右的顺序给出,即对所有 1≤i≤n−1,满足 yi≤xi+1。
输出格式
Print one real value, the fastest possible time to reach L. Your answer will be considered correct if its absolute or relative error won't exceed 10−9.
输出一个实数值,即到达 L 的最短可能时间。若您的答案的绝对或相对误差不超过 10−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 0 to 2 with speed 2.0 and Limak wants to get to point 5. The second example has a walkway from 2 to 4 with speed 0.91.

In the first example, one of optimal strategies is as follows.
- Get from 0 to 2 by standing still on the walkway. It moves you with speed 2 so it takes 1 second and you save up 1 energy.
- Get from 2 to 4 by walking with max speed 2 for next 1 second. It takes 1 second again and the energy drops to 0.
- Get from 4 to 5 by walking with speed 1. It takes 1 second and the energy stays constant at the value 0.
The total time is 1+1+1=3.
示意图展示了前两个例子。在第一个例子中,有一条从 0 到 2 的自动步道,其速度为 2.0,Limak 需要到达位置 5。第二个例子中有一条从 2 到 4 的自动步道,其速度为 0.91。

在第一个例子中,一种最优策略如下:
- 从 0 到 2,静止站在自动步道上。步道以速度 2 带你前进,耗时 1 秒,同时你节省了 1 单位能量。
- 从 2 到 4,以最大速度 2 行走 1 秒。再次耗时 1 秒,能量降至 0。
- 从 4 到 5,以速度 1 行走。耗时 1 秒,能量保持为 0 不变。
总时间为 1+1+1=3。
输入解题思路,AI测评打分。不知道怎么写?