Codeforces Round 1092 (Unrated, Div. 1, Based on THUPC 2026 — Finals)
E
Star Map
Codeforces
2700
原题
← DF →
翻译中…

Funni-chan loves watching stars.

翻译中…

There are $n$ stars in the sky, which can be regarded as points on a plane with Cartesian coordinates. The coordinates of the $i$-th star are $(x_i, y_i)$. It is guaranteed that all $x_1, x_2, \ldots, x_n$ are pairwise distinct, and all $y_1, y_2, \ldots, y_n$ are pairwise distinct. The stars are numbered from $1$ to $n$ in the order they are given in the input.

翻译中…

Funni-chan wants to connect some pairs of these stars to form a constellation.

翻译中…

She defines the basic unit of a constellation as a triangle formed by three stars connected pairwise. A triangle is called harmonious if there exists an axis-aligned rectangle such that all three vertices of the triangle lie on the boundary of the rectangle.

翻译中…

Funni-chan imposes the following constraints on the constellation:

翻译中…
  • Every triangle in the constellation must be harmonious.
  • The interiors of any two triangles in the constellation must be disjoint. Note that the boundary of a triangle is not considered part of its interior.
翻译中…

Under these constraints, Funni-chan wants her constellation to contain the maximum possible number of triangles. Your task is to find this maximum number and construct a valid constellation that achieves it.

翻译中…

Input

翻译中…

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 2\cdot 10^4$). The description of the test cases follows.

翻译中…

The first line of each test case contains a single integer $n$ ($3 \le n \le 2 \cdot 10^5$) — the number of stars.

翻译中…

Each of the next $n$ lines contains two integers $x_i$ and $y_i$ ($-10^9\le x_i, y_i \le 10^9$) — the coordinates of the $i$-th star. It is guaranteed that all $x_i$-s are pairwise distinct, and all $y_i$-s are pairwise distinct.

翻译中…

It is guaranteed that the sum of $n$ over all test cases does not exceed $2\cdot 10^5$.

翻译中…

Output

翻译中…

In the first line of each test case, you should print a single integer $m$ ($0\le m\le 2\cdot n$) — the maximum possible number of triangles in the constellation.

翻译中…

Then $m$ lines follow, each line containing three distinct positive integers $a_i$, $b_i$, and $c_i$ ($1 \le a_i, b_i, c_i \le n$), denoting the indices of the three stars forming the $i$-th triangle.

翻译中…

Note

翻译中…

The first test case of the example is illustrated below:

翻译中…

image

翻译中…

The second test case of the example is illustrated below:

翻译中…

image

翻译中…

样例

Input #1
2
8
-10 1
-2 6
5 10
8 -9
-1 -2
3 0
0 3
1 -8
8
8 8
-5 3
-4 1
5 7
10 10
-3 5
-8 -10
-7 -1
Output #1
8
6 5 8
6 8 4
1 6 5
7 1 6
2 7 1
3 2 7
3 7 6
3 6 4
2
2 3 8
6 2 3
InputCopy OutputCopy
题目信息
题号
2215E
时间限制
2 s
内存限制
256 MB
标签
构造
数据结构
计算几何
贪心
排序

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