CF1237C2.Balanced Removals (Harder)
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
This is a harder version of the problem. In this version, n≤50000 .
There are n distinct points in three-dimensional space numbered from 1 to n . The i -th point has coordinates (xi,yi,zi) . The number of points n is even.
You'd like to remove all n points using a sequence of 2n snaps. In one snap, you can remove any two points a and b that have not been removed yet and form a perfectly balanced pair. A pair of points a and b is perfectly balanced if no other point c (that has not been removed yet) lies within the axis-aligned minimum bounding box of points a and b .
Formally, point c lies within the axis-aligned minimum bounding box of points a and b if and only if min(xa,xb)≤xc≤max(xa,xb) , min(ya,yb)≤yc≤max(ya,yb) , and min(za,zb)≤zc≤max(za,zb) . Note that the bounding box might be degenerate.
Find a way to remove all points in 2n snaps.
输入格式
The first line contains a single integer n ( 2≤n≤50000 ; n is even), denoting the number of points.
Each of the next n lines contains three integers xi , yi , zi ( −108≤xi,yi,zi≤108 ), denoting the coordinates of the i -th point.
No two points coincide.
输出格式
Output 2n pairs of integers ai,bi ( 1≤ai,bi≤n ), denoting the indices of points removed on snap i . Every integer between 1 and n , inclusive, must appear in your output exactly once.
We can show that it is always possible to remove all points. If there are many solutions, output any of them.
输入输出样例
输入#1
6 3 1 0 0 3 0 2 2 0 1 0 0 1 3 0 0 1 0
输出#1
3 6 5 1 2 4
输入#2
8 0 1 1 1 0 1 1 1 0 1 1 1 2 2 2 3 2 2 2 3 2 2 2 3
输出#2
4 5 1 6 2 7 3 8
说明/提示
In the first example, here is what points and their corresponding bounding boxes look like (drawn in two dimensions for simplicity, as all points lie on z=0 plane). Note that order of removing matters: for example, points 5 and 1 don't form a perfectly balanced pair initially, but they do after point 3 is removed.