logo AlgoBeat OnlineJudge
登录 注册

#210690. [HBCPC2024] Lili Likes Polygons

内存限制:512 MiB 时间限制:1000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

Lili and Nana are weeding in the backyard of Lili’s house. They are repeatedly selecting rectangular areas and removing all the grass within them.

The backyard can be visualized as a 2D grid, each square cell representing one unit area. They have performed a total of operations. During the -th operation, they choose the left, bottom, right, and top sides of a rectangle, denoted as , and clear all the cells within this rectangle using a lawnmower. Note that these rectangles may overlap with each other.

Let denote a rectangle.

Here is an example illustrated in the following figure. They have selected rectangles, with the first rectangle being and the second rectangle being .

After the weeding operations, the union of the bare area may not be connected but all the sides are horizontal or vertical. Thus, the union becomes orthogonal polygon(s), some of which contain polygon holes. Moreover, there can be bare cells inner some holes. Please see the example inputs for more details and illustrations.

Now, they want to restore the land by planting some plants on the bare cells. Lili likes polygons, especially rectangles. Therefore, they want to select several rectangles, and these rectangles do not overlap with each other and exactly cover all the bare cells. Then, they plant different plants in different rectangles they selected.

For example, here is a feasible selection of rectangles for the aforementioned case: choose , and .

After playing for a while, these two little girls have become tired, so they want to know the minimum number of non-overlapping rectangles that can cover all the bare cells.

输入格式

The first line contains a single integer () --- the number of rectangles when they weed.

The following lines each contain integers, and the -th line contains () --- the left, bottom, right, and top sides of the -th rectangle.

It is guaranteed the sum of the endpoints of the bare area (polygon(s) with polygonal holes) does not exceed .

输出格式

Output a single integer on a single line denoting the minimum number of rectangles they need to select to plant plants on all the bare cells.

样例

样例输入 1

8
1 1 1 1
1 2 1 2
1 3 1 3
2 1 2 1
2 3 2 3
3 1 3 1
3 2 3 2
3 3 3 3

样例输出 1

4

样例输入 2

2
1 1 100 100
1 501 100 600

样例输出 2

2

样例输入 3

4
1 1 4 1
1 4 5 4
1 1 1 4
4 1 4 5

样例输出 3

5

样例输入 4

9
1 1 9 1
1 1 1 9
1 9 9 9
9 1 9 9
3 3 7 3
3 3 3 7
3 7 7 7
7 3 7 7
5 5 5 5

样例输出 4

9

数据范围与提示

For the first example, an optimal selection is , , and .

For the second example, an optimal selection is and .

For the third example, an optimal selection is , , , and .

For the fourth example, the bare area is illustrated in the following figure.