CF1237C2.Balanced Removals (Harder)

普及+/提高

通过率:0%

时间限制:1.00s

内存限制:512MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

This is a harder version of the problem. In this version, n≤50 000n \le 50\,000.

There are nn distinct points in three-dimensional space numbered from 11 to nn. The ii-th point has coordinates (xi,yi,zi)(x_i, y_i, z_i). The number of points nn is even.

You'd like to remove all nn points using a sequence of n2\frac{n}{2} snaps. In one snap, you can remove any two points aa and bb that have not been removed yet and form a perfectly balanced pair. A pair of points aa and bb is perfectly balanced if no other point cc (that has not been removed yet) lies within the axis-aligned minimum bounding box of points aa and bb.

Formally, point cc lies within the axis-aligned minimum bounding box of points aa and bb if and only if min⁡(xa,xb)≤xc≤max⁡(xa,xb)\min(x_a, x_b) \le x_c \le \max(x_a, x_b), min⁡(ya,yb)≤yc≤max⁡(ya,yb)\min(y_a, y_b) \le y_c \le \max(y_a, y_b), and min⁡(za,zb)≤zc≤max⁡(za,zb)\min(z_a, z_b) \le z_c \le \max(z_a, z_b). Note that the bounding box might be degenerate.

Find a way to remove all points in n2\frac{n}{2} snaps.

这是一个更难的版本。在此版本中,n≤50 000n \le 50\,000。

在三维空间中有 nn 个互不相同的点,编号从 11 到 nn。第 ii 个点的坐标为 (xi,yi,zi)(x_i, y_i, z_i)。点的总数 nn 是偶数。

你希望用 n2\frac{n}{2} 次“点击”(snap)操作移除全部 nn 个点。每次点击操作中,你可以任选两个尚未被移除的点 aa 和 bb 并将其同时移除,前提是它们构成一个“完美平衡对”(perfectly balanced pair)。点对 aa 和 bb 被称为完美平衡对,当且仅当不存在其他尚未被移除的点 cc 位于点 aa 和 bb 的轴对齐最小包围盒(axis-aligned minimum bounding box)内部。

形式化地,点 cc 位于点 aa 和 bb 的轴对齐最小包围盒内部,当且仅当

min⁡(xa,xb)≤xc≤max⁡(xa,xb),min⁡(ya,yb)≤yc≤max⁡(ya,yb),min⁡(za,zb)≤zc≤max⁡(za,zb).\min(x_a, x_b) \le x_c \le \max(x_a, x_b),\quad \min(y_a, y_b) \le y_c \le \max(y_a, y_b),\quad \min(z_a, z_b) \le z_c \le \max(z_a, z_b).

注意:该包围盒可能退化(即某维长度为零)。

请找出一种方案,在 n2\frac{n}{2} 次点击操作内移除所有点。

输入格式

The first line contains a single integer nn (2≤n≤50 0002 \le n \le 50\,000; nn is even), denoting the number of points.

Each of the next nn lines contains three integers xix_i, yiy_i, ziz_i (−108≤xi,yi,zi≤108-10^8 \le x_i, y_i, z_i \le 10^8), denoting the coordinates of the ii-th point.

No two points coincide.

第一行包含一个整数 nn(2≤n≤50 0002 \le n \le 50\,000;nn 为偶数),表示点的个数。

接下来的 nn 行,每行包含三个整数 xix_i、yiy_i、ziz_i(−108≤xi,yi,zi≤108-10^8 \le x_i, y_i, z_i \le 10^8),表示第 ii 个点的坐标。

任意两个点均不重合。

输出格式

Output n2\frac{n}{2} pairs of integers ai,bia_i, b_i (1≤ai,bi≤n1 \le a_i, b_i \le n), denoting the indices of points removed on snap ii. Every integer between 11 and nn, 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.

输出 n2\frac{n}{2} 对整数 ai,bia_i, b_i(1≤ai,bi≤n1 \le a_i, b_i \le n),表示第 ii 次“快照”(snap)中被移除的点的下标。11 到 nn(含端点)之间的每个整数在你的输出中必须恰好出现一次。

我们可以证明:总是存在一种方式将所有点全部移除。若存在多种解,输出任意一种即可。

输入输出样例

  • 输入#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=0z = 0 plane). Note that order of removing matters: for example, points 55 and 11 don't form a perfectly balanced pair initially, but they do after point 33 is removed.

在第一个示例中,下图展示了各点及其对应的边界框(为简化起见,在二维平面上绘制,因为所有点均位于 z=0z = 0 平面上)。注意:移除点的顺序至关重要。例如,点 55 和点 11 最初并不构成一个完全平衡的点对,但在点 33 被移除后,它们便构成了一个完全平衡的点对。

输入解题思路,AI测评打分。不知道怎么写?

首页