Horizontally Visible Segments
Time limit1sMemory limit128 MB
Given disjoint vertical segments, count triangles formed by triples that are pairwise horizontally visible using a sweep and visibility structure.
- Level
Hard8 of 10
- Topics
- Sorting, Geometry, Segment tree
- Solved
- No attempts yet
Problem
You are given a set of pairwise disjoint vertical line segments in the plane (no two segments share any point).
Two segments are said to be horizontally visible if they can be joined by a horizontal segment that has no common point with any other vertical segment. Three distinct vertical segments form a triangle of segments if each of the three pairs among them is horizontally visible.
For each data set, read the description of a set of vertical segments and report how many triangles of segments it contains.
Input
The first line contains one positive integer , the number of data sets, with . The data sets follow.
The first line of each data set contains one integer with , the number of vertical segments. Each of the next lines contains three non-negative integers , , separated by single spaces: the -coordinate of the lower endpoint, the -coordinate of the upper endpoint, and the -coordinate of the -th segment. The coordinates satisfy and , and the segments are pairwise disjoint.
Output
Print exactly lines, one per data set. The -th line must contain a single integer: the number of triangles of segments in the -th data set.