#P8246. [COCI 2013/2014 #3] ODAŠILJAČI
[COCI 2013/2014 #3] ODAŠILJAČI
Problem Description
On a 2D plane, there is a line segment of length , whose left endpoint is at the origin, and which lies on the axis. There are also segments that are perpendicular to the axis, whose feet lie on segment , and which are above the axis. For the -th segment, its distance from the origin is , and its length is .
Besides segment , the top endpoints of some segments have a negligible-sized light point installed, which can emit lasers to its left and right. A laser can only travel along a straight line, and it cannot pass through any segment (including segment ). We say a point on segment is covered if and only if there exists some light point such that it emits a laser in some direction and the laser finally lands on point .
Now, compute the total length of all covered parts on segment .
Please refer to the samples and sample explanations to better understand the statement.
Input Format
The first line contains two integers , representing the number of segments other than segment and the length of segment , respectively.
The next lines each contain three integers , representing whether the top endpoint of the -th segment has a light point, the distance of the -th segment from the origin, and its length. Specifically, if , it means the top endpoint of the -th segment has no light point; otherwise, it means the top endpoint has a light point.
Output Format
Output a real number, the total length of all covered parts on segment . You must ensure that the relative error between your output and the standard answer does not exceed .
3 10
1 2 6
0 4 3
0 8 2
6.000000
5 15
0 4 3
1 5 5
1 6 6
0 9 2
0 10 3
8.500000
Hint
Sample 2 Explanation
The figure below corresponds to sample 2, where the bold parts are the uncovered areas.

Constraints and Limits
This problem uses bundled testdata. The score and special limits for each subtask are as follows:
- Subtask 1 (48 pts): .
- Subtask 2 (112 pts): no special limits.
For all testdata, , , , , . It is guaranteed that , . It is guaranteed that is strictly increasing.
Source
This problem is from COCI 2013-2014 CONTEST 3 T6 ODAŠILJAČI, and with the original data configuration, the full score is points.
Translated, organized, and provided by Eason_AC.
Translated by ChatGPT 5