CF1192A.Building Skyscrapers

普及/提高-

通过率:0%

时间限制:3.50s

内存限制:1024MB

AC君温馨提醒

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

题目描述

We are going to build a new city: the Metropolis. The city is going to be built on an infinite square grid. The finished city will consist of nn skyscrapers, each occupying a different cell of the grid. At any moment during the construction, the cells that currently do not contain a skyscraper are called empty.

You are given the planned coordinates of the nn skyscrapers. Your task is to find an order in which they can be built while satisfying the rules listed below.

  • The building crew has only one crane, so the Metropolis has to be constructed one skyscraper at a time.
  • The first skyscraper can be built anywhere on the grid.
  • Each subsequent skyscraper has to share a side or a corner with at least one of the previously built skyscrapers (so that it's easier to align the new skyscraper to the grid properly).
  • When building a skyscraper, there has to be a way to deliver material to the construction site from the outside of Metropolis by only moving it through empty cells that share a side. In other words, there should be a path of side-adjacent empty cells that connects the cell that will contain the skyscraper to some cell (r,c)(r,c) with ∣r∣>109|r| \gt 10^9 and/or ∣c∣>109|c| \gt 10^9.

If a solution exists, let's denote the numbers of skyscrapers in the order in which they should be built by s1,…,sns_1, \dots, s_n. There are two types of subtasks:

Type 1: You may produce any valid order.

Type 2: You must find the order that maximizes sns_n. Among those, you must find the one that maximizes sn−1s_{n-1}. And so on. In other words, you must find the valid order of building for which the sequence (sn,sn−1,…,s1)(s_n,s_{n-1},\dots,s_1) is lexicographically largest.

我们将建造一座新城市:大都会(Metropolis)。这座城市将建在一个无限大的正方形网格上。建成后的城市将包含 nn 座摩天大楼,每座大楼占据网格中一个不同的格子。在建设过程中的任意时刻,尚未建造摩天大楼的格子称为空闲格子。

你将获得 nn 座摩天大楼的规划坐标。你的任务是找出一种建造顺序,使其满足以下规则:

  • 建设队伍只有一台起重机,因此大都会必须逐座建造摩天大楼。
  • 第一座摩天大楼可以建在网格上的任意位置。
  • 后续每一座摩天大楼必须与至少一座已建成的摩天大楼共享一条边或一个角(以便更方便地将新大楼精确对齐到网格上)。
  • 在建造某座摩天大楼时,必须存在一条从大都会外部向该建筑工地运送建材的路径,且该路径仅经过空闲格子,且路径中相邻格子必须共享一条边。换言之,必须存在一条由边相邻的空闲格子构成的路径,将即将建造摩天大楼的格子与某个满足 ∣r∣>109|r| \gt 10^9 或 ∣c∣>109|c| \gt 10^9 的格子 (r,c)(r,c) 连接起来。

若解存在,记按建造顺序编号的摩天大楼序列为 s1,…,sns_1, \dots, s_n。本题分为两类子任务:

类型 1:输出任意一个合法顺序即可。

类型 2:你必须找出使 sns_n 最大的建造顺序;在所有使 sns_n 最大的方案中,再找出使 sn−1s_{n-1} 最大的方案;依此类推。换句话说,你必须找出一个合法的建造顺序,使得序列 (sn,sn−1,…,s1)(s_n,s_{n-1},\dots,s_1) 的字典序最大。

输入格式

The first line contains a single integer nn (1≤n≤150,0001 \le n \le 150,000) – the number of skyscrapers.

The second line contains a single integer tt (1≤t≤21 \le t \le 2) describing the type of the subtask as defined above.

Then, nn lines follow. The ii-th of these lines contains two space-separated integers rir_i and cic_i (∣ri∣,∣ci∣≤109|r_i|, |c_i| \le 10^9) denoting the coordinates of the cell containing skyscraper ii.

(The skyscrapers are not numbered in any particular order. The only reason why they have numbers is that they are used in the output format.)

It is guaranteed that no two skyscrapers coincide.

第一行包含一个整数 nn(1≤n≤150,0001 \le n \le 150{,}000),表示摩天大楼的数量。

第二行包含一个整数 tt(1≤t≤21 \le t \le 2),表示子任务类型,定义如上。

接下来是 nn 行。其中第 ii 行包含两个以空格分隔的整数 rir_i 和 cic_i(∣ri∣,∣ci∣≤109|r_i|, |c_i| \le 10^9),表示第 ii 座摩天大楼所在单元格的坐标。

(这些摩天大楼并未按任何特定顺序编号;编号仅用于输出格式中。)

保证任意两座摩天大楼的位置均不重合。

输出格式

If it is impossible to build the skyscrapers according to the given rules, print a single line containing the string "NO".

Otherwise, print n+1n+1 lines. The first of these lines should contain the string "YES". For each ii, the ii-th of the remaining nn lines should contain a single integer sis_i.

In subtasks with t=1t = 1, if there are multiple valid orders, you may output any one of them.

如果无法按照给定规则建造摩天大楼,则输出一行字符串 "NO"。

否则,输出 n+1n+1 行。其中第一行应包含字符串 "YES";对于每个 ii,剩余 nn 行中的第 ii 行应包含一个整数 sis_i。

在 t=1t = 1 的子任务中,若存在多种合法的排列顺序,你可以输出其中任意一种。

输入输出样例

  • 输入#1

    3
    2
    0 0
    0 1
    0 2

    输出#1

    YES
    1
    2
    3
  • 输入#2

    3
    1
    0 0
    1 1
    2 2

    输出#2

    YES
    2
    3
    1
  • 输入#3

    2
    1
    0 0
    0 2

    输出#3

    NO

说明/提示

In the first example, there are three skyscrapers in a row. All of them can always be reached from outside the Metropolis, and there are four build orders which preserve connectivity:

  • 1, 2, 3
  • 2, 1, 3
  • 2, 3, 1
  • 3, 2, 1

Since t=2t = 2, we must choose the first option.

In the second example, the only difference from the first example is that skyscraper 2 shares only corners with skyscrapers 1 and 3, the same set of orders as in the first sample is valid. Since t=1t = 1, each of these answers is correct.

In the third example, the Metropolis is disconnected. We obviously can't build that.

在第一个例子中,一行中有三座摩天大楼。它们全部始终可以从大都市外部到达,且有四种保持连通性的建造顺序:

  • 1, 2, 3
  • 2, 1, 3
  • 2, 3, 1
  • 3, 2, 1

由于 t=2t = 2,我们必须选择第一种方案。

在第二个例子中,与第一个例子的唯一区别在于:摩天大楼 2 仅与摩天大楼 1 和 3 共享角点,因此与第一个样例相同的顺序集合仍然有效。由于 t=1t = 1,这些答案中的任意一个都是正确的。

在第三个例子中,该大都市是不连通的。显然我们无法进行这样的建造。

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

首页