QOJ.ac

QOJ

Time Limit: 2.0 s Memory Limit: 256 MB Total points: 100

#15890. Rectangle Connections

Statistics

MCO Land 可以被建模为一个无限大的二维网格。网格的行从下到上编号为 $0,1,2,\ldots$,列从左到右编号为 $0,1,2,\ldots$。位于第 $x$ 列、第 $y$ 行的格子称为格子 $(x,y)$。

MCO Land 由 $m$ 个行政区(district)组成。每个行政区可以建模为网格中的一个矩形子网格。第 $i$ 个行政区用四个整数 $(x_{i,1},x_{i,2},y_{i,1},y_{i,2})$ 表示,其中 $x_{i,1}\le x_{i,2}$ 且 $y_{i,1}\le y_{i,2}$。这表示该行政区包含所有满足 $x_{i,1}\le x\le x_{i,2}$ 且 $y_{i,1}\le y\le y_{i,2}$ 的格子 $(x,y)$。

MCO Land 的领导者 Evirir 想要修建邮局和道路来服务所有行政区。

初始时没有道路。首先,Evirir 可以免费修建若干条水平或垂直道路来连接行政区。形式化地说,当且仅当满足下列条件之一时,行政区 $i$ 与 $j$ 之间可以用一条道路连接:

  • 区间 $[x_{i,1},x_{i,2}]$ 与 $[x_{j,1},x_{j,2}]$ 相交(允许只在边界相交),或者
  • 区间 $[y_{i,1},y_{i,2}]$ 与 $[y_{j,1},y_{j,2}]$ 相交(允许只在边界相交)。

特别地,如果两个行政区的矩形发生重叠,那么它们一定可以被道路连接。

之后,Evirir 可以选择任意多个行政区,并在每个被选中的行政区内修建一个邮局。最终,所有行政区都必须(直接或间接)连接到至少一个邮局。若一个行政区本身包含邮局,或可以沿道路到达某个包含邮局的行政区,则称该行政区与该邮局连通。

道路可以跨越其他道路或行政区。然而,如果一条道路与另一条道路在某个位置相交,不能在交点处从一条道路切换到另一条道路(道路为立交桥)。

请问 Evirir 需要修建的邮局数量最少是多少?

输入格式

第一行包含一个整数 $m$($1\le m\le 2\cdot 10^5$),表示 MCO Land 中行政区的数量。

接下来 $m$ 行中,第 $i$ 行包含四个用空格分隔的整数 $x_{i,1}$、$x_{i,2}$、$y_{i,1}$、$y_{i,2}$($0\le x_{i,1}\le x_{i,2}\le 10^9$,$0\le y_{i,1}\le y_{i,2}\le 10^9$),表示第 $i$ 个行政区 $(x_{i,1},x_{i,2},y_{i,1},y_{i,2})$。

输出格式

输出一个整数,表示需要修建的最少邮局数量。

样例数据

输入

5
1 2 1 2
2 4 7 8
0 0 4 4
6 7 3 4
7 8 4 6

输出

2

说明

problem_15890_1.png

在该样例中,有三条道路分别连接了行政区 $1$ 与 $2$、$3$ 与 $4$、$4$ 与 $5$。Evirir 可以在行政区 $1$ 和 $4$ 各建一个邮局。这样,行政区 $1$ 与 $2$ 连接到行政区 $1$ 的邮局,行政区 $3$、$4$、$5$ 连接到行政区 $4$ 的邮局。可以证明只建 $1$ 个邮局是不够的。

注意:尽管道路在格子 $(2,4)$ 处相交,你也不能在此处换路。因此例如行政区 $1$ 与 $3$ 并不连通。

子任务

子任务 1($4$ 分)

存在某个常数 $c$,使得对所有 $1\le i\le m$,都有 $y_{i,1}=y_{i,2}=c$。

子任务 2($16$ 分)

$m\le 2000$,且对所有 $1\le i\le m$,$0\le x_{i,1},x_{i,2},y_{i,1},y_{i,2}\le 2000$。

子任务 3($9$ 分)

$m\le 2000$。

子任务 4($12$ 分)

对所有 $1\le i\le m$,$x_{i,1}=x_{i,2}$ 且 $y_{i,1}=y_{i,2}$。

子任务 5($32$ 分)

对所有 $1\le i\le m$,$y_{i,1}=y_{i,2}=i$。

子任务 6($14$ 分)

对所有 $1\le i\le m-1$,$x_{i,1}\le x_{i+1,1}$ 且 $y_{i,1}\le y_{i+1,1}$。

子任务 7($13$ 分)

无额外限制。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.