Codeforces Round 573 (Div. 1)
D
Tokitsukaze and Strange Rectangle
Codeforces
2000
原题
← CE →
翻译中…

There are $n$ points on the plane, the $i$-th of which is at $(x_i, y_i)$. Tokitsukaze wants to draw a strange rectangular area and pick all the points in the area.

翻译中…

The strange area is enclosed by three lines, $x = l$, $y = a$ and $x = r$, as its left side, its bottom side and its right side respectively, where $l$, $r$ and $a$ can be any real numbers satisfying that $l \lt r$. The upper side of the area is boundless, which you can regard as a line parallel to the $x$-axis at infinity. The following figure shows a strange rectangular area.

翻译中…

image

翻译中…

A point $(x_i, y_i)$ is in the strange rectangular area if and only if $l \lt x_i \lt r$ and $y_i \gt a$. For example, in the above figure, $p_1$ is in the area while $p_2$ is not.

翻译中…

Tokitsukaze wants to know how many different non-empty sets she can obtain by picking all the points in a strange rectangular area, where we think two sets are different if there exists at least one point in one set of them but not in the other.

翻译中…

Input

翻译中…

The first line contains a single integer $n$ ($1 \leq n \leq 2 \times 10^5$) — the number of points on the plane.

翻译中…

The $i$-th of the next $n$ lines contains two integers $x_i$, $y_i$ ($1 \leq x_i, y_i \leq 10^9$) — the coordinates of the $i$-th point.

翻译中…

All points are distinct.

翻译中…

Output

翻译中…

Print a single integer — the number of different non-empty sets of points she can obtain.

翻译中…

Note

翻译中…

For the first example, there is exactly one set having $k$ points for $k = 1, 2, 3$, so the total number is $3$.

翻译中…

For the second example, the numbers of sets having $k$ points for $k = 1, 2, 3$ are $3$, $2$, $1$ respectively, and their sum is $6$.

翻译中…

For the third example, as the following figure shows, there are

翻译中…
  • $2$ sets having one point;
  • $3$ sets having two points;
  • $1$ set having four points.
翻译中…

Therefore, the number of different non-empty sets in this example is $2 + 3 + 0 + 1 = 6$.

翻译中…

image

翻译中…

样例

Input #1
3
1 1
1 2
1 3
Output #1
3
InputCopy OutputCopy
Input #2
3
1 1
2 1
3 1
Output #2
6
InputCopy OutputCopy
Input #3
4
2 1
2 2
3 1
3 2
Output #3
6
InputCopy OutputCopy
题目信息
题号
1190D
时间限制
3 s
内存限制
256 MB
标签
数据结构
分治
排序
双指针

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。