QOJ.ac

QOJ

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

#2853. Paint by Rectangles

الإحصائيات

After her previous artwork was met with critical acclaim, Bessie was offered a job designing painting sets. She designs these paintings by choosing $1\le N\le 10^5$ axis-aligned rectangles in the plane such that no two edges are collinear. The boundaries of these rectangles define the boundaries of the painting's colored regions.

Still being an avant-garde artist, Bessie decides that the painting should resemble a Holstein cow. More specifically, each region formed by the rectangles is colored either black or white, no two adjacent regions have the same color, and the region outside of all the rectangles is colored white.

After choosing the rectangles, Bessie would like you to output one of two things based on a parameter $T$:

  • If $T=1$, output the total number of regions.
  • If $T=2$, output the number of white regions followed by the number of black regions.

Note: the time limit for this problem is 4s, twice the default.

Input Format

The first line contains $N$ and $T$.

The next $N$ lines each contain the description of a rectangle in the form $(x_1,y_1), (x_2,y_2)$ where $1\le x_1<x_2\le 2N$ and $1\le y_1<y_2\le 2N$. $(x_1, y_1)$ and $(x_2, y_2)$ are the bottom left and top right corners of the rectangle respectively.

It is guaranteed that all the $x_i$ form a permutation of $1\ldots 2N$, and the same holds for all the $y_i$.

Output Format

A single integer if $T=1$, otherwise two separated by spaces.

Sample Input 1

2 1
1 1 3 3
2 2 4 4

Sample Output 1

4

There are two white regions and two black regions, for a total of four regions. The boundaries of all rectangles are connected, so this input would satisfy the conditions of subtask 3.

problem_2853_1.png

Sample Input 2

5 2
1 5 3 6
5 4 7 9
4 1 8 3
9 8 10 10
2 2 6 7

Sample Output 2

4 5

The boundary of the rectangle in the upper-right is not connected to the rest of the boundaries, so this input would not satisfy the conditions of subtask 4.

problem_2853_2.png

Scoring

  1. Test cases 3-4 satisfy $N\le 10^3$.
  2. In test cases 5-7, no two rectangle boundaries intersect.
  3. In test cases 8-10, $T=1$ and the boundaries of all rectangles are connected.
  4. In test cases 11-13, $T=2$ and the boundaries of all rectangles are connected.
  5. In test cases 14-18, $T=1$.
  6. In test cases 19-23, $T=2$.

Problem credits: Andi Qu

About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.