#P2449. [SDOI2005] 矩形

[SDOI2005] 矩形

Description

We have drawn nn rectangles on a plane. Each rectangle has its sides parallel to the coordinate axes, and all vertex coordinates are integers. We define a shape that satisfies the following properties to be a block:

  1. Each rectangle is a block.

  2. If two blocks have a segment of overlap, then these two blocks form a new block; otherwise, the two blocks are different.

Example:

In Figure 11, the rectangles form two different blocks. In Figure 22, the rectangles form one block.

Task:

Please write a program to:

  1. Read the vertex coordinates of each rectangle from standard input.
  2. Find the number of different blocks among these rectangles.
  3. Output the result to standard output.

Input Format

The first line contains an integer nn, where 1n70001\le n\le 7000, the number of rectangles. Each of the next nn lines gives the vertex coordinates of a rectangle. Each rectangle is described by four integers: the xx-coordinate of the lower-left corner, the yy-coordinate of the lower-left corner, the xx-coordinate of the upper-right corner, and the yy-coordinate of the upper-right corner. All coordinates are non-negative integers not greater than 1000010000.

Output Format

Output a single integer — the number of different blocks formed by these rectangles.

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

2

Hint

Image link

The thick orange segments indicate where overlaps occur. The number in the center of each square denotes the ID of the block it belongs to.

Note: Corner touching does not count as the same block.

Translated by ChatGPT 5