#K65182. Non-Intersecting Rod Pairs
Non-Intersecting Rod Pairs
Non-Intersecting Rod Pairs
You are given a set of n rods, where each rod is described by a pair of integers (x, y). Here, x represents the horizontal coordinate and y represents the height of the rod. All rods have distinct x-coordinates.
Two rods are considered non-intersecting if they do not overlap in height when considering their vertical lines. Given that the rods are placed at distinct x-coordinates, any two rods will not intersect. Therefore, the problem reduces to finding the number of ways to choose 2 rods out of n, which can be computed using the formula:
\(\binom{n}{2} = \frac{n(n-1)}{2}\)
inputFormat
The input begins with a single integer n (1 \(\leq n \leq 10^5\)), representing the number of rods. This is followed by n lines, each containing two space-separated integers x and y, where x is the rod's position and y is its height. It is guaranteed that all x values are distinct.
outputFormat
Output a single integer representing the number of non-intersecting pairs of rods, which is given by \(\frac{n(n-1)}{2}\).
## sample3
1 3
2 1
3 4
3