Dominoes
Time limit2sMemory limit1024 MB
Given n dominoes that fall left with heights l_i, find for each starting domino the area of the union of quarter circles that topple.
- Level
Hard8 of 10
- Topics
- Stack, Dynamic programming, Geometry
- Solved
- No attempts yet
Statement
Pixar is preparing to premiere its next animated film, Elemental, at the 2023 Cannes Film Festival. One scene needs to be re-rendered. The scene has dominoes in a straight line. When one of them falls, it knocks over the dominoes after it in a chain. The festival is less than a month away, so Pixar asks you to write a program that computes the cost of re-rendering the scene for each choice of the initial domino.
To keep the calculation simple, treat each domino as a line segment with no width on the coordinate axis. The dominoes fall to the left. They are numbered from left to right, and domino has height and is located at . The cost of re-rendering is the area of the moving part of the scene, which is the union of the quarter circles traced by the dominoes that fall. Falling areas may overlap, and any overlapped area is counted only once. The picture shows the fall when domino 5 is the initial domino.
Input
The first line contains a positive integer , the number of dominoes. Each of the next lines contains two integers and , the location and the height of domino . The dominoes are given from left to right, so . It is guaranteed that and .
Output
Output lines. The -th line contains the cost of re-rendering the scene when domino is the initial falling domino. Every number must have an absolute or relative error of at most .