Jump Civilization

Time limit: 1s Memory limit: 512MB Input: Output:

"Here in Parkour Jump Civilization, No One Chooses to Jump for the Beef" ━ Evbo - Parkour Civilization, the movie

Task

In jump civilization, the world consists of NN floating islands, numbered 11 to NN. When at island ii (for 1i<N1 \leq i < N), the members of jump civilization can either take:

  • an easy jump, from island ii to island i+1i + 1; or
  • a difficult jump, from island ii to island viv_i, where i<viNi < v_i \leq N.

In order to rank up in jump civilization, the members of jump civilization need to compute the jumping power of each island. The jumping power of island ii is the number of islands which can be reached by starting at island ii and using at most KK jumps.

The previous Jump Champion, wanting to make sure that the jumping course is fair, instituted the following important rule: Whenever 1i<jN1 \leq i < j \leq N, either vijv_i \leq j or vjviv_j \leq v_i.

You, as an aspiring member of jump civilization, want to find the jumping power of every island - can you do this efficiently?

Input data

The first line of the input contains two space-separated integers NN, KK. The second line of the input contains N1N - 1 space-separated integers v1,,vN1v_1, \dots, v_{N - 1}.

Output data

Output NN space-separated integers, the jumping power of the islands in order.

Constraints and clarifications

  • 1N300 0001 \leq N \leq 300 \ 000
  • 1KN11 \leq K \leq N - 1
  • i<viNi < v_i \leq N
  • For 1i<jN1 \leq i < j \leq N, either vijv_i \leq j or vjviv_j \leq v_i.
  • If island jj can be reached from island ii in two different ways using at most KK jumps, then the island is only counted once for the jumping power of island ii.
  • When computing the jumping power of an island, it doesn't matter whether we use easy or difficult jumps — only the number of jumps matters.
# Points Restrictions
1 6 N2 000N \leq 2 \ 000
2 27 N100 000N \leq 100 \ 000 and K50K \leq 50
3 11 vii+2v_i \leq i + 2 for 1i<N1 \leq i < N
4 37 N100 000N \leq 100 \ 000
5 19 No additional constraints

Example 1

stdin

5 1
4 3 4 5

stdout

3 2 2 2 1

Explanations

From island 11, one can reach island 11 without jumping, and islands 22 and 44 with 11 jump. In total, the jumping power of island 11 is 33.

Example 2

stdin

6 2
2 3 5 5 6

stdout

3 4 4 3 2 1

Log in or sign up to be able to send submissions!