아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Paint by Rectangles

시간 제한4초메모리 제한1024 MB

요약
서로 겹치는 축에 나란한 직사각형들이 이루는 영역의 개수를 세고, 요청 시 바깥을 흰색으로 두는 체커보드 색칠에서 흰 영역과 검은 영역의 수를 각각 구합니다.
난이도

보통10점 중 7점

유형
기하, 그래프, DFS, 구현
정답자
아직 제출이 없습니다

문제

After her previous artwork was met with critical acclaim, Bessie was offered a job designing painting sets. She designs these paintings by choosing 1≤N≤1051\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 TT:

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

입력

The first line contains NN and TT.

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

It is guaranteed that all the x_ix\_i form a permutation of 1…2N1\ldots 2N, and the same holds for all the y_iy\_i.

출력

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

예제2

  1. 예제 1

    입력
    2 1
    1 1 3 3
    2 2 4 4
    
    예상 출력
    4
    
  2. 예제 2

    입력
    5 2
    1 5 3 6
    5 4 7 9
    4 1 8 3
    9 8 10 10
    2 2 6 7
    
    예상 출력
    4 5