TopCoder

User's AC Ratio

NaN% (0/0)

Submission's AC Ratio

NaN% (0/0)

Tags

Description


Contemporary buildings can have very complicated roofs. If we take a
vertical section of such a roof it amounts to a number of sloping segments.
When it is raining the drops are falling down onto the roof straight from
the sky above. Some segments are completely exposed to the rain but there
may be some segments partially or even completely shielded by other segments.
All the water falling onto a segment flows as a stream straight down from the
lower end of the segment on the ground or possibly onto some other segment.
In particular if a stream of water is falling on an end of a segment then we
consider it to be collected by this segment.



<!-- MATH
$\epsfbox{p2947.eps}$
-->
ALIGN="BOTTOM" BORDER="0"
SRC="/ntujudge/problemdata/607-1.gif"
ALT="\epsfbox{p2947.eps}">


For the purpose of designing a piping system it is
desired to compute how much water is flowing down from each segment of the
roof. To be prepared for a heavy November rain you should count one liter
of rain water falling on a meter of the horizontal plane during one second.




Write a program that:

  • reads the description of the roof from the standard input,
  • computes the amount of water flowing down in one second from each segment of the roof,
  • writes the result to the standard output.

Input Format


Input consists of several test cases separated by a blank line.


The first line of each dataset contains one integer n (<!-- MATH
$1 \le n \le 40000$
-->
1 WIDTH="18" HEIGHT="30" ALIGN="MIDDLE" BORDER="0"
SRC="/ntujudge/problemdata/607-2.png"
ALT="$ \le$">n WIDTH="18" HEIGHT="30" ALIGN="MIDDLE" BORDER="0"
SRC="/ntujudge/problemdata/607-2.png"
ALT="$ \le$">40000
)
being the number of segments of the roof. Each of the next n lines
describes one segment of the roof and contains four integers

x1, y1, x2, y2 (<!-- MATH
$0 \le x_{1}, y_{1}, x_{2}, y_{2} \le 1000000$
-->
0 WIDTH="18" HEIGHT="30" ALIGN="MIDDLE" BORDER="0"
SRC="/ntujudge/problemdata/607-2.png"
ALT="$ \le$">x1, y1, x2, y2 WIDTH="18" HEIGHT="30" ALIGN="MIDDLE" BORDER="0"
SRC="/ntujudge/problemdata/607-2.png"
ALT="$ \le$">1000000
,

x1 < x2, <!-- MATH
$y_{1} != y_{2}$
-->
y1 != y2) separated by single spaces.
Integers x1, y1 are
respectively the horizontal position and the height of the left end of the
segment. Integers x2, y2 are respectively the horizontal position and
the height of the right end of the segment. The segments don't have common
points and there are no horizontal segments. Also you can assume that
there are at most 100 segments placed above any point on the ground level.

Output Format


For each test case, the output consists of n lines. The i-th line should contain the amount
of water (in liters) flowing down from the i-th segment of the roof during
one second.

The outputs of two consecutive cases will be separated by a blank line.

Sample Input 1


6
13 7 15 6
3 8 7 7
1 7 5 6
5 5 9 3
6 3 8 2
9 6 12 8

Sample Output 1


2
4
2
11
0
3

Hints

Problem Source

Migrated from old NTUJ.

CEPC 2003

Subtasks

No. Testdata Range Score

Testdata and Limits

No. Time Limit (ms) Memory Limit (VSS, KiB) Output Limit (KiB) Subtasks
0 10000 65536 4096