Problem:
Score : 500 points

Problem Statement

We have N bulbs arranged on a number line, numbered 1 to N from left to right.
Bulb i is at coordinate i.

Each bulb has a non-negative integer parameter called intensity.
When there is a bulb of intensity d at coordinate x, the bulb illuminates the segment from coordinate x-d-0.5 to x+d+0.5.
Initially, the intensity of Bulb i is A_i. We will now do the following operation K times in a row:

For each integer i between 1 and N (inclusive), let B_i be the number of bulbs illuminating coordinate i. Then, change the intensity of each bulb i to B_i.

Find the intensity of each bulb after the K operations.

Constraints

1 \leq N \leq 2 \times 10^5

1 \leq K \leq 2 \times 10^5

0 \leq A_i \leq N

Input

Input is given from Standard Input in the following format:

N K
A_1 A_2 \ldots A_N

Output

Print the intensity A{'}_i of each bulb i after the K operations to Standard Output in the following format:

A{'}_1 A{'}_2 \ldots A{'}_N

Sample Input 1

5 1
1 0 0 1 0

Sample Output 1

1 2 2 1 2

Initially, only Bulb 1 illuminates coordinate 1, so the intensity of Bulb 1 becomes 1 after the operation.
Similarly, the bulbs initially illuminating coordinate 2 are Bulb 1 and 2, so the intensity of Bulb 2 becomes 2.

Sample Input 2

5 2
1 0 0 1 0

Sample Output 2

3 3 4 4 3

Solution in Rust (1.42.0) (judge verdict: Accepted)

#![allow(non_snake_case,unused_imports,dead_code)]
use std::io::Read;
use std::cmp::max;
use std::cmp::min;
use std::str::FromStr;
use std::collections::HashMap;
use std::collections::HashSet;
use std::collections::BinaryHeap;
use std::cmp::Ordering;

fn comp_f64(a: &f64, b: &f64) -> Ordering {
    if a < b {
        return Ordering::Less;
    } else if a > b {
        return Ordering::Greater;
    }
    Ordering::Equal
}

fn main() {

    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut buf_it = buf.split_whitespace();


    let N = buf_it.next().unwrap().parse::<usize>().unwrap();
    let K = buf_it.next().unwrap().parse::<usize>().unwrap();

    let A = (0..N).map(|_| buf_it.next().unwrap().parse::<isize>().unwrap()).collect::<Vec<_>>();

    let mut B = A.iter().map(|&a| a).collect::<Vec<_>>();
    let B_INF = (0..N).map(|i| min(max(i,N-i)+10,N) as isize).collect::<Vec<_>>();
    let mut cnt_INF = 0;
    let mut I = (0..N).collect::<HashSet<_>>();
    for _ in 0..(K-1){
        if cnt_INF == N as isize { break;}
        let mut T = SegmentTree::new(N,|x,y| x+y,0);
        for &i in &I{
            let a = B[i];
            let l = max(0,i as isize -a) as usize;
            let r = min(N,i+a as usize +1);
            T.set(l,r,1);
        }
        let mut i_POP = Vec::new();
        for &i in &I{
            B[i] = T.get(i) + cnt_INF;
            if B[i] >= B_INF[i]{
                i_POP.push(i);
            }
        }
        for &i in &i_POP{
            I.remove(&i);
            cnt_INF += 1;
        }
    }
    
    let mut T = SegmentTree::new(N,|x,y| x+y,0);
    for i in 0..N{
        let a = B[i];
        let l = max(0,i as isize -a) as usize;
        let r = min(N,i+a as usize +1);
        T.set(l,r,1);
    }
    for i in 0..N{
        B[i] = T.get(i);
    }
    for b in &B{
        println!("{}",b);
    }

}

struct SegmentTree<N,F>
where F:Fn(N,N) ->N{
//モノイドが乗るセグ木(区間更新一点取得)
    n: usize,
    T: Vec<N>,
    func: F,
    identity: N,
}

impl<N:Copy,F> SegmentTree<N,F>
where F:Fn(N,N) ->N {
    fn new(n:usize,func:F,identity:N) -> SegmentTree<N,F>{
        let mut T = SegmentTree { n:n,T:Vec::new(),func:func,identity:identity};
        T.init();
        T
    }
    fn init(&mut self){
        self.n = 1<<format!("{:b}",self.n-1).len();
        self.T = (0..(2*self.n-1)).map(|_| self.identity).collect();
    }
    fn get(&mut self,index:usize) -> N{
        let i = index + self.n - 1;
        self._get(i)
    }
    fn _get(&mut self,i:usize) -> N{
        let n = self.T[i];
        if i==0{return n;}
        let m = self._get((i-1)/2);
        (self.func)(n,m)
    }
    fn set(&mut self,l:usize,r:usize,value:N){
        let n = self.n;
        self._set(l,r,value,0,0,n);
    }
    fn _set(&mut self,l:usize,r:usize,value:N,i:usize,a:usize,b:usize){
        if l==a && b==r{
            let v = self.T[i];
            let v = (self.func)(v,value);
            self.T[i] = v;
            return;
        }
        let j = (a+b)/2;
        if l<j{
            self._set(l,min(r,j),value,2*i+1,a,j);
        }
        if j<r{
            self._set(max(l,j),r,value,2*i+2,j,b);
        }
    }
}