PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#PS0000248. Diện tích giấy chồng lên nhau (Cluttered Paper)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Diện tích giấy chồng lên nhau (Cluttered Paper)

Cluttered Paper

Source: AtCoder

Version: Phuoc Hung OJ Extended

Problem Statement

There are NN axis-aligned rectangular sheets on a plane. Sheet ii has lower-left corner (lxi,lyi)(lx_i,ly_i) and upper-right corner (rxi,ryi)(rx_i,ry_i). For every k=1,2,…,Nk=1,2,\ldots,N, compute the area covered by exactly kk sheets. Coincident sheets count separately; boundary-only intersections contribute zero area.

Input

First line: NN. Each of the next NN lines contains lxi,lyi,rxi,ryilx_i,ly_i,rx_i,ry_i in that order.

Output

Print NN lines. Line kk contains the integer area covered by exactly kk sheets, including zero values.

Subtasks

  • Subtask 1 (20 points): 1≤N≤301\le N\le 30; 0≤lxi<rxi≤300\le lx_i<rx_i\le 30; 0≤lyi<ryi≤300\le ly_i<ry_i\le 30.
  • Subtask 2 (30 points): 1≤N≤1000001\le N\le 100000; 0≤lxi<rxi≤10000\le lx_i<rx_i\le 1000; 0≤lyi<ryi≤10000\le ly_i<ry_i\le 1000; all rectangles have identical coordinates.
  • Subtask 3 (50 points): 1≤N≤1000001\le N\le 100000; 0≤lxi<rxi≤10000\le lx_i<rx_i\le 1000; 0≤lyi<ryi≤10000\le ly_i<ry_i\le 1000.

Example 1

Input

2
1 1 3 2
2 1 4 2

Output

2
1

Explanation

Each sheet has area 2 and their intersection has area 1. Exactly one sheet covers area 2.

Example 2

Input

2
1 1 3 4
3 4 6 5

Output

9
0

Explanation

The sheets touch only at a corner, with areas 6 and 3.

Example 3

Input

20
61 98 76 100
70 99 95 100
10 64 96 91
12 37 99 66
63 93 65 95
16 18 18 67
30 47 88 56
33 6 38 8
37 19 40 68
4 56 12 84
3 16 92 78
39 24 67 96
46 1 69 57
40 34 65 65
20 38 51 92
5 32 100 73
7 33 92 55
4 46 97 85
43 18 57 87
15 29 54 74

Output

1806
990
1013
1221
567
839
413
305
228
121
58
40
0
0
0
0
0
0
0
0

Explanation

Exactly one layer covers area 1806, exactly 12 layers cover area 40, and no positive area has 13 or more layers.