QOJ.ac

QOJ

実行時間制限: 1 s メモリ制限: 64 MB 満点: 100

#23196. Colored Paper

統計

$N$ rectangular sheets of colored paper, each of a different color, are placed on a plane one at a time in order. 

No sheet is placed at an angle. In other words, any two edges of the sheets are either parallel or perpendicular. 

Figure 1 shows sheets 1, 2, and 3 placed in that order.

 

problem_23196_00b389f7b25e3479ad975c889c4e4882.png

 

If one more sheet, number 4, is placed as shown in Figure 2, sheet 3 becomes completely covered and cannot be seen. 

Sheets 1 and 2 are partially covered, while sheet 4 is entirely visible.

 

problem_23196_3a5e2bb653337d502a674da446b5959c.png

 

Write a program that finds the visible area of each sheet when $N$ sheets are placed in order at the given positions.

 

Input

The first input line contains an integer $N$ ($1 \le N \le 100$), the number of sheets. The next $N$ lines describe the sheets in order, one sheet per line.

The plane on which the sheets are placed is a grid with at most $1001$ cells horizontally and $1001$ cells vertically. 

Each grid cell is a square of width $1$, height $1$, and area $1$. 

For convenience, consider an example grid with $6$ cells horizontally and $6$ vertically. The value $(a, b)$ marked in each cell identifies that cell. 

The bottom-left cell is $(0, 0)$, and the top-right cell is $(5, 5)$.

problem_23196_daeca5fa2fe213bb1a63990b319437c9.png

The placement of a sheet is represented by four integers specifying the identifier of its bottom-left cell, its width, and its height. 

For example, the gray sheet in the figure above has bottom-left cell $(1, 4)$, width $3$, and height $2$, so it is represented as `1 4 3 2`. 

No sheet extends outside the grid boundaries. 

Constraints 

Subtask 1: $11$ points out of $100$; $N = 1$. 

Subtask 2: $12$ points out of $100$; $N \le 10$, and every sheet has width $1$ and height $1$. The plane is a grid of $101$ cells horizontally and $101$ vertically. 

Subtask 3: $30$ points out of $100$; $N \le 10$, and the plane is a grid of $101$ cells horizontally and $101$ vertically. 

Subtask 4: $47$ points out of $100$; there are no constraints beyond the original ones.

Output

After placing the $N$ sheets on the plane in input order, print the visible area of each sheet in input order, as one integer per line.

If a sheet is not visible, print the integer $0$.

Examples

Input 1

2
0 0 10 10
2 2 6 6

Output 1

64
36

Input 2

3
0 2 10 10
7 9 8 4 
8 4 10 6

Output 2

81
25
60

Input 3

4
0 2 10 10 
7 9 8 4 
8 4 10 6
6 0 12 10

Output 3

62
24
0
120

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.