Painting the Fence
Time limit2sMemory limit1024 MB
After each prefix of n painted segments, report the largest visible color, where overlapping segments merge into groups colored by their mean.
- Level
Medium7 of 10
- Topics
- Intervals, Segment tree, Union-find
- Solved
- No attempts yet
Statement
Young Anakin Skywalker received a seemingly simple task from Master Yoda. He has to paint a fence with a special paint. The task consists of subtasks. Each subtask paints a segment of the fence with a given color. Colors are integers. Like any other paint, the paint Anakin got changes its color after it dries, but in an unusual way. Two segments intersect if their intersection has nonzero area. At first, each painted segment is its own group. While there are two intersecting segments that belong to different groups and , merge and . Repeat until no such pair remains. The color of a group is the arithmetic mean of the colors of its segments. Knowing this value for each group, we can find the color of any point of the fence after the paint dries. A point belongs to a group if at least one segment of that group contains it. A point that belongs to no group has color . Otherwise it has the color of its group. A point cannot belong to two groups. While painting, Anakin wondered what happens if he finishes after the first segments are painted. In particular, he asked: what is the largest color that can be found on the fence after the paint dries?
Input
The first line contains one integer (), the number of fence segments to paint. Each of the next lines contains three integers , , (, ). The segment is , so the left end is included and the right end is not. is the color used to paint this segment.
Output
Print real numbers, one per line, with at least three digits after the decimal point. The number on line is the largest color of a point on the fence that can be found if Anakin finishes after the first subtasks.