Under construction

Still being built. Things may change

Bicycle Stunts

Interview

Time limit1sMemory limit1024 MB

Summary
For each starting cell, count how many cells the rider steps on when riding forward over ramps on a road of N cells.
Level

Easy3 of 10

Topics
Dynamic programming, Array
Solved
No attempts yet

Problem

A straight bicycle road is NN meters long. The road is divided into NN cells of 1 meter each, numbered 1, 2, …, NN from the leftmost cell.

Each cell may have a jump ramp. Let hih_i be the height of the ramp in cell ii. When a rider steps on a ramp of height hih_i, the rider flies over the next hih_i cells regardless of any other factor and lands on the cell after them. Look at this example.

Starting from cell 1 and riding forward, the following happens in order.

  1. Cell 1 has no ramp, so the rider moves to cell 2.
  2. Cell 2 has a ramp of height 1, so the rider flies over cell 3 and lands on cell 4.
  3. Cell 4 has a ramp of height 2, so the rider flies over cells 5 and 6 and lands on cell 7.
  4. Cell 7 has no ramp, so the rider moves to cell 8.
  5. Cell 8 has a ramp of height 3, so the rider flies over cell 9 and goes far ahead. (If the road were long enough, the rider would have landed on the imaginary cell 12.)

Sieun wants to know how many cells the rider steps on when riding forward from each starting cell. Testing all NN cells one by one is tedious. Sieun built the table below and noticed that the answer for a cell can be computed from the answer for a cell to its right.

Starting cellAnswerCells stepped on
151, 2, 4, 7, 8
242, 4, 7, 8
343, 4, 7, 8
434, 7, 8
535, 7, 8
636, 7, 8
727, 8
818
919

Cell 1 has no ramp, so its answer is the answer for cell 2 plus 1. Cell 2 has a ramp of height 1, so its answer is the answer for cell 4 plus 1, skipping one cell. The other cells work the same way. Cells 8 and 9 have answer 1, since the rider steps on only cell 8 and only cell 9, respectively, and then leaves the road.

Input

The first line contains NN, the length of the road.

The second line contains the ramp heights for cells 1 through NN, in order, separated by spaces. A cell with no ramp is given as 0.

Output

For cells 1 through NN, in order, print the number of cells the rider steps on when starting from that cell and riding forward. Separate the numbers with spaces.

Constraints

  • 1≤N≤200,0001 \le N \le 200,000
  • 1≤1 \le ramp height ≤200,000\le 200,000

Examples3

  1. Example 1

    Input
    9
    0 1 0 2 1 0 0 3 0
    
    Expected output
    5 4 4 3 3 3 2 1 1
    
  2. Example 2

    Input
    10
    1 0 0 5 0 0 3 0 0 0
    
    Expected output
    4 4 3 2 3 2 1 3 2 1
    
  3. Example 3

    Input
    1
    200000
    
    Expected output
    1