CF928B.Chat

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

There are times you recall a good old friend and everything you've come through together. Luckily there are social networks — they store all your message history making it easy to know what you argued over 10 years ago.

More formal, your message history is a sequence of messages ordered by time sent numbered from 11 to nn where nn is the total number of messages in the chat.

Each message might contain a link to an earlier message which it is a reply to. When opening a message xx or getting a link to it, the dialogue is shown in such a way that kk previous messages, message xx and kk next messages are visible (with respect to message xx ). In case there are less than kk messages somewhere, they are yet all shown.

Digging deep into your message history, you always read all visible messages and then go by the link in the current message xx (if there is one) and continue reading in the same manner.

Determine the number of messages you'll read if your start from message number tt for all tt from 11 to nn . Calculate these numbers independently. If you start with message xx , the initial configuration is xx itself, kk previous and kk next messages. Messages read multiple times are considered as one.

输入格式

The first line contains two integers nn and kk ( 1<=n<=1051<=n<=10^{5} , 0<=k<=n0<=k<=n ) — the total amount of messages and the number of previous and next messages visible.

The second line features a sequence of integers a1,a2,...,ana_{1},a_{2},...,a_{n} ( 0<=a_{i}<i ), where aia_{i} denotes the ii -th message link destination or zero, if there's no link from ii . All messages are listed in chronological order. It's guaranteed that the link from message xx goes to message with number strictly less than xx .

输出格式

Print nn integers with ii -th denoting the number of distinct messages you can read starting from message ii and traversing the links while possible.

输入输出样例

  • 输入#1

    6 0
    0 1 1 2 3 2
    

    输出#1

    1 2 2 3 3 3 
    
  • 输入#2

    10 1
    0 1 0 3 4 5 2 3 7 0
    

    输出#2

    2 3 3 4 5 6 6 6 8 2 
    
  • 输入#3

    2 2
    0 1
    

    输出#3

    2 2 
    

说明/提示

Consider i=6i=6 in sample case one. You will read message 66 , then 22 , then 11 and then there will be no link to go.

In the second sample case i=6i=6 gives you messages 5,6,75,6,7 since k=1k=1 , then 4,5,64,5,6 , then 2,3,42,3,4 and then the link sequence breaks. The number of distinct messages here is equal to 66 .

首页