[Solution] Multi-Colored Segments Codeforces Solution
Dmitry has segments of different colors on the coordinate axis . Each segment is characterized by three integers , and (), where and are are the coordinates of the ends of the -th segment, and is its color.
Dmitry likes to find the minimum distances between segments. However, he considers pairs of segments of the same color uninteresting. Therefore, he wants to know for each segment the distance from this segment to the nearest differently colored segment.
The distance between two segments is the minimum of the distances between a point of the first segment and a point of the second segment. In particular, if the segments intersect, then the distance between them is equal to .
For example, Dmitry has segments:
- The first segment intersects with the second (and these are segments of different colors), so the answers for them are equal to .
- For the -rd segment, the nearest segment of a different color is the -nd segment, the distance to which is equal to .
- For the -th segment, the nearest segment of a different color is the -th segment, the distance to which is equal to .
- The -th segment lies inside the -nd segment (and these are segments of different colors), so the answers for them are equal to .
The first line of the input contains an integer () — the number of test cases in the test.
The descriptions of the test cases follow.
The first line of description of each test case contains one integer () — the number of segments.
The next lines contain descriptions of the segments. Each segment is described by three integers , and () — coordinates of the left and right ends of -th segment, as well as the color of this segment. It is guaranteed that there are at least segments of different colors.
It is guaranteed that the sum of over all test cases does not exceed .
For each test case, on a separate line print integers, where the -th number is equal to the distance from the -th segment to the nearest segment of a different color.
No comments:
Post a Comment