[ICPC2017 WF] Visual Python++

题意翻译

# 题意 有 $n$ 个矩形,每个矩形左上角为 $(r_1,c_1)$ ,右下角为 $(r_2,c_2)$。 矩形可以嵌套(矩形包含在其他矩形中)任意层。在合法的情况下,任意两个矩形要么是嵌套的(一个包含在另一个中),要么是不交的(不重叠)。在这两种情况中,他们的 **边界也不能重叠**。 # 输入格式 第一行包含一个整数 $n(1\leq n \leq 10^5)$ ,表示矩形的数量。 接下来 $n$ 行,每行两个整数 $r$ 和 $c(1\leq r,c\leq 10^9)$ ,指定 $(r,c)$ 为第 $i$ 个左上角坐标。 接下来 $n$ 行,每行两个整数 $r$ 和 $c(1\leq r,c\leq 10^9)$ ,指定 $(r,c)$ 为第 $j$ 个右下角坐标。 所有给定坐标互不相同。 # 输出格式 输出 $n$ 行,每行包含一个整数。第 $i$ 行整数 $j$ 表示第 $i$ 个左上角和第 $j$ 个右下角组成一个矩形。左上角和右下角均按照他们在输入中的顺序从 $1$ 到 $n$ 标号。输出必须是 $1$ 到 $n$ 的排列,从而匹配可能嵌套的矩形。如果存在超过一种合法的匹配,任意一组合法的匹配都是可接受的。如果不存在合法的匹配,输出 `syntax error`。

题目描述

In the recently proposed Visual Python++ programming language, a block of statements is represented as a rectangle of characters with top-left corner in row $r_{1}$ and column $c_{1},$ and bottom-right corner in row $r_{2}$ and column $c_{2}.$ All characters at locations $(r , c)$ with $r_{1} \le r \le r_{2}$ and $c_{1} \le c \le c_{2}$ are then considered to belong to that block. Among these locations, the ones with $r = r_{1}$ or $r = r_{2}$ or $c = c_{1}$ or $c = c_{2}$ are called a border. Statement blocks can be nested (rectangles contained in other rectangles) to an arbitrary level. In a syntactically correct program, every two statement blocks are either nested (one contained in the other) or disjoint (not overlapping). In both cases, their borders may not overlap. Programmers are not expected to draw the many rectangles contained in a typical program $-$ this takes too long, and Visual $Pytho_n++$ would not have a chance to become the next ICPC programming language. So a programmer only has to put one character $‘p'$ in the top-left corner of the rectangle and one character $‘y'$ in the bottom-right corner. The parser will automatically match up the appropriate corners to obtain the nesting structure of the program. Your team has just been awarded a five-hour contract to develop this part of the parser.

输入输出格式

输入格式


The first line of the input contains an integer $n (1 \le n \le 10^{5}),$ the number of corner pairs. Each of the next $n$ lines contains two integers $r$ and $c (1 \le r , c \le 10^{9}),$ specifying that there is a top-left corner in row $r$ and column $c$ of the program you are parsing. Following that are $n$ lines specifying the bottom-right corners in the same way. All corner locations are distinct.

输出格式


Display $n$ lines, each containing one integer. A number $j$ in line $i$ means that the $i^{th}$ top-left corner and the $j^{th}$ bottom-right corner form one rectangle. Top-left and bottom-right corners are each numbered from $1$ to $n$ in the order they appear in the input. The output must be a permutation of the numbers from $1$ to $n$ such that the matching results in properly nested rectangles. If there is more than one valid matching, any one will be accepted. If no such matching exists, display syntax error.

输入输出样例

输入样例 #1

2
4 7
9 8
14 17
19 18

输出样例 #1

2
1

输入样例 #2

2
4 7
14 17
9 8
19 18

输出样例 #2

1
2

输入样例 #3

2
4 8
9 7
14 18
19 17

输出样例 #3

syntax error

输入样例 #4

3
1 1
4 8
8 4
10 6
6 10
10 10

输出样例 #4

syntax error

说明

Time limit: 5 s, Memory limit: 512 MB.