#P14370. [ICPC 2024 NAC] Shadow Line
[ICPC 2024 NAC] Shadow Line
Problem Description
There is a point light source at the origin (0, 0) in the plane.
To the right, at x = w, there is an infinitely tall vertical wall.
Between the light source and the wall there are several opaque vertical line segments.
Each segment casts a shadow onto the wall, and the union of all shadows forms one or more intervals on the wall.

Now move the light source leftward along the negative x-axis.
As the light source moves, the shadows on the wall also change, and the number of shaded intervals may change as well.
Your task is to compute the total length of all x-axis positions for which the shadows on the wall form exactly one shaded interval.
If this total includes an unbounded interval (that is, there is already exactly one shaded interval when the light source is infinitely far away), output -1.
Answers within absolute or relative error 1e-6 are accepted.
Input
The first line contains two integers n and w:
1 <= n <= 30002 <= w <= 10^6
where:
nis the number of opaque vertical segments,wis the x-coordinate of the infinitely tall wall.
Each of the next n lines contains three integers:
x ylow yhigh
subject to:
0 < x < w-10^6 <= ylow < yhigh <= 10^6
Each line describes a vertical segment from (x, ylow) to (x, yhigh).
Additional guarantees:
- all y-coordinates are distinct,
- no two segments intersect or overlap.
Output
Output a single number: the sum of the lengths of the x-axis intervals for which the wall receives exactly one shaded interval.
If this sum is unbounded, output -1.
Your answer will be accepted if its absolute or relative error is at most 1e-6.
Sample Input 1
3 20
2 1 3
6 -4 2
12 -10 -5
Sample Output 1
16.0