Rectangles | 프로그래밍의 벗 PivotOJ
PivotOJ

Rectangles

시간 제한: 1000ms메모리 제한: 128MB출처: NOI 1999BOJ 9927
이 문제는 본문 이미지 일부가 표시되지 않습니다. 텍스트만으로 풀이가 어려울 수 있습니다.

문제

A rectangle whose edges are parallel to the axes can always be defined by the two ends of one of its diagonals. For example, a rectangle can be drawn when the top left (x1,y1)(x_1, y_1) and the bottom right (x2,y2)(x_2, y_2) coordinates are given.

[이미지 1]

Given a set of rectangles, we are interested in finding the total area covered by them. For instance, the total area covered by the rectangles below is the area covered within the solid lines. Notice that there is no double counting for overlapping regions.

[이미지 2]

Write a program that, given a set of rectangles, computes the total area covered by all the rectangles.

입력

The input describes a set of NN rectangles where NN ranges between 0 to 1000. On the first line is the integer NN. The remaining lines are the coordinates of the rectangle. In each of these line, the two points (x1,y1)(x_1, y_1) and (x2,y2)(x_2, y_2) are given as 4 integers x1,y1,x2,y2x_1, y_1, x_2, y_2 separated by one or more blanks. Note that they are NOT necessarily the top-left and bottom-right coordinates. In addition, xix_i and yiy_i take the value between 0 to 3276732767.

출력

On the first line of output, your program must write the total area covered by the rectangles. You may assume that the area is at most 32767.

예제

예제 1

입력
4
20 5 0 15
37 26 14 9
20040 2 20050 18
17 22 33 15
출력
715
코드를 제출하려면 로그인하세요.