JOI '05 Final Round P5 - Sheets

View as PDF

Submit solution

Points: 15 (partial)
Time limit: 0.25s
Memory limit: 128M

Problem type

There are many rectangular sheets placed on the plane. Your task is to write a program to calculate the area covered by the sheets, as well as the length of the circumference surrounding the area. We assume the standard coordinate system to represent the sheets on the plane. The sheets are arranged so that the following conditions are satisfied:

  1. The x- and y- coordinates of four vertices of each sheet are integers between 0 and 10000.
  2. Each side of any sheet is parallel to either the x-axis or the y-axis.
  3. The number of sheets is at most 10000.

Constraints

In 40% of test data, the coordinates of vertices of sheets are between 0 and 100. In half of these test cases, r=1

In 50% of test data, r=1.

Input

The first line contains 2 integers n, the number of sheets, and r, the type of the problem, separated by a single space character. The i + 1-st line contains four integers x_1, y_1, x_2 and y_2 in this order, separated by a single space character between them, to represent the left-lower coordinate (x_1, y_1) and the right-upper coordinate (x_2, y_2) of the i-th sheet.

Output

The area should be output on the first line in case r = 1. The length of the cicumference should be output on the second line additionally in case r = 2.

Sample Input 1

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

Sample Output 1

29

Sample Input 2

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

Sample Output 2

29
38

Sample Input 3

2 2
0 0 8 9
0 0 9 8

Sample Output 3

80
36

Sample Input 4

3 2
2 2 8 9
3 0 4 9
5 0 7 9

Sample Output 4

48
34

Comments

There are no comments at the moment.