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 C++ (GCC 9.2.1) (judge verdict: Time Limit Exceeded)

#include <bits/stdc++.h>
using namespace std;

using ll = long long;

#include<bits/stdc++.h>

// https://onlinejudge.u-aizu.ac.jp/status/users/hamuhei4869/submissions/1/DSL_2_G/judge/4384116/C++11

template<typename T>
class LazySegmentTree{
    //[l, r)半開区間を扱う
private:
    std::vector<T> node, lazy;
    std::function<T(T, T)> f; // 取得の演算
    std::function<T(T, T)> g; // 更新の演算
    std::function<T(T, int)> pow; // 更新の演算をk回作用させたときの結果

    T f_ide; //演算fの単位元
    T g_ide; //演算gの単位元

    int size;
public:
    LazySegmentTree(int n, std::function<T(T, T)> f, std::function<T(T, T)> g, T f_ide, T g_ide) : 
    f(f),
    g(g),
    f_ide(f_ide),
    g_ide(g_ide)
    {
        init(n);
        pow = [&](T a, int k){
            T ans = g_ide;
            while(k > 0){
                if(k & 1)ans = g(ans, a);
                a = g(a, a);
                k >>= 1;
            }
            return ans;
        };
    }
    LazySegmentTree(int n, std::function<T(T, T)> f, std::function<T(T, T)> g, std::function<T(T, int)> pow, T f_ide, T g_ide) : 
    f(f),
    g(g),
    pow(pow),
    f_ide(f_ide),
    g_ide(g_ide)
    {
        init(n);
    }
    void init(int n){
        size = 1;
        while(size < n)size *= 2;
        node = std::vector<T>(2 * size - 1, f_ide);
        lazy = std::vector<T>(2 * size - 1, g_ide);
    }
    void eval(int k, int l, int r){
        node[k] = g(node[k], pow(lazy[k], r - l));

        if(r - l >= 2){
            lazy[2 * k + 1] = g(lazy[2 * k + 1], lazy[k]);
            lazy[2 * k + 2] = g(lazy[2 * k + 2], lazy[k]);
        }

        lazy[k] = g_ide;
    }
    void update(int a, int b, T x, int k = 0, int l = 0, int r = -1){
        if(r < 0)r = size;
        if(r <= a || b <= l)return;
        
        if(a <= l && r <= b){
            lazy[k] = g(lazy[k], x);
            eval(k, l, r);
        }else{
            update(a, b, x, 2 * k + 1, l, (l + r) / 2);
            update(a, b, x, 2 * k + 2, (l + r) / 2, r);
            eval(2 * k + 1, l, (l + r) / 2);
            eval(2 * k + 2, (l + r) / 2, r);

            node[k] = f(node[2 * k + 1], node[2 * k + 2]);
        }
    }
    T get(int a, int b, int k = 0, int l = 0, int r = -1){
        if(r < 0)r = size;
        if(r <= a || b <= l)return f_ide;

        eval(k, l, r);

        if(a <= l && r <= b){
            return node[k];
        }else{
            T result_left = get(a, b, 2 * k + 1, l, (l + r) / 2);
            T result_right = get(a, b, 2 * k + 2, (l + r) / 2, r);
            return f(result_left, result_right);
        }
    }
};

void solve(long long N, long long K, std::vector<long long> A){
    std::function<long long(long long, long long)> f = [](long long a, long long b){
        return a + b;
    };
    std::function<ll(ll, int)> pow = [](ll a, int b){
        return a * b;
    };
    auto g = f;
    for(int i = 0;i < K;i++){
        LazySegmentTree<long long> Seg(N, f, g, pow, 0, 0);
        /*
        for(int j = 00;j < N;j++){
            cout<<A[j]<<" ";
        }
        cout<<endl;
        */
        for(int i = 0;i < N;i++){
            Seg.update(max(0LL, i - A[i]), min(N, i + A[i] + 1), 1);
        }
        bool w = true;
        vector<ll> u = A;
        for(int j = 0;j < N;j++){
            A[j] = Seg.get(j, j+1);
        }
        if(u == A){
            break;
        }
    }
    for(int i = 00;i < N;i++){
        cout<<A[i]<<" ";
    }
    cout<<endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long K;
    scanf("%lld",&K);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, K, std::move(A));
    return 0;
}