Rectangles

축에 평행한 직사각형을 그릴 때마다 해당 픽셀의 흑백이 반전된다고 할 때, 최대 100,000개의 직사각형을 모두 그린 뒤 검은 픽셀의 개수를 구한다.

어려움8기하세그먼트 트리누적 합정렬아직 제출이 없습니다시간 제한2초메모리 제한512 MB

문제

You are working on a new graphics system, which has added a new feature. Whenever you draw a figure, all the pixels in that figure flip from white to black, or from black to white. This image is what happens when three overlapping rectangles are drawn on a white field:

Starting with a white field, given a series of axis-aligned rectangles, how many pixels end up black?

입력

Each input will consist of a single test case. Note that your program may be run multiple times on different inputs.

Each test case will begin with a line with a single integer n (1 ≤ n ≤ 100,000) indicating the number of rectangles.

Each of the next n lines will have four space-separated integers x1, y1, x2 and y2 (0 ≤ x1 < x2 ≤ 109, 0 ≤ y1 < y2 ≤ 109) which represent opposite corners of a rectangle. The rectangle consists of all pixels (x,y) such that x1 ≤ x < x2 and y1 ≤ y < y2, so the area of the rectangle is (x2 - x1) × (y2 - y1) pixels.

출력

Output a single integer, which is the number of pixels that are black after all of the rectangles are drawn on a white field.