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++ (Clang 10.0.0) (judge verdict: Accepted)

//{{{
#include<algorithm>
#include<cmath>
#include<deque>
#include<fstream>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<random>
#include<set>
#include<sstream>
#include<sys/time.h>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(printde) FUNC(printdbe) FUNC(printdwe) FUNC(printdu) FUNC(printe) FUNC(printe0);
#endif
template <template <class T, class = std::allocator<T>> class V, class E>
istream& operator >> (istream& in, V<E>& v){ for(auto& e : v){ in >> e; } return in; }
//}}}

struct Watch {
    double prev;
    double getPrev(){
        return prev;
    }
#ifdef LOCAL
    timeval start;
    Watch(){
        gettimeofday(&start, nullptr);
    }
    double elapsed(){
        timeval now;
        gettimeofday(&now, nullptr);
        return prev = (now.tv_sec - start.tv_sec) + (now.tv_usec - start.tv_usec) / 1e6;
    }
#else
    double start;
#define ticks_per_sec 2800000000.0
    Watch(){
        start = get_time();
    }
    double elapsed(){
        return prev = get_time() - start;
    }
private:
    double get_time(){
        uint32_t lo, hi;
        asm volatile ("rdtsc" : "=a" (lo), "=d" (hi));
        return (((uint64_t)hi << 32) | lo) / ticks_per_sec;
    }
#endif
} watch;

// int cnt;
struct SegTree {
    int l = -1, r;
    // SegTree *l, *r;
    int left, right;
    static vector<SegTree> sts;
    int value = 0;
    SegTree() = default;
    SegTree(vector<int>& data):SegTree(0, data.size() - 1, data){ }
    SegTree(int st, int lt, vector<int>& data): left(st), right(lt){
        if(left == right){
            l = r = -1;
            // l = r = nullptr;
            value = data[left];
        }else{
            l = sts.size();
            // printde(1, sts.size());
            sts.push_back({});
            auto s1 = SegTree(left, (right - left) / 2 + left, data);
            sts[l] = s1;
            // sts.emplace_back(left, (right - left) / 2 + left, data);
            // printde(2, sts.size());

            r = sts.size();
            sts.push_back({});
            auto s2 = SegTree((right - left) / 2 + left + 1, right, data);
            sts[r] = s2;
            // sts.emplace_back(s2);
            // sts.emplace_back((right - left) / 2 + left + 1, right, data);
            // l = new SegTree(left, (right - left) / 2 + left, data);
            // r = new SegTree((right - left) / 2 + left + 1, right, data);
        }
    }
    void set0(){
        if(l >= 0){
            sts[l].set0();
            sts[r].set0();
        }
        // if(l){
        //     l->set0();
        //     r->set0();
        // }
        value = 0;
    }
    void add(int st, int lt, int val){
        // cnt++;
        if(right < st || lt < left){ return; }
        if(st <= left && right <= lt){
            value += val;
        }else{
            sts[l].add(st, lt, val);
            sts[r].add(st, lt, val);
            // l -> add(st, lt, val);
            // r -> add(st, lt, val);
        }
    }
	int getVal(int idx){
        // cnt++;
        if(right < idx || idx < left){ return 0; }
        return value + (l >= 0 ? sts[l].getVal(idx) + sts[r].getVal(idx) : 0);
        // return value + (l ? l->getVal(idx) + r->getVal(idx) : 0);
	}
};
vector<SegTree> SegTree::sts;

int main(){
    Watch watch;
    cin.tie(0); ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    vector<int> as(n); cin >> as;

    // int n = 2e5, k = 1000;
    // vector<int> as(n, 0);

    SegTree st(as);

    // {
    //     vector<int> next;
    //     for(int i = 0; i < k; i++){
    //         printde(i, as);
    //
    //         if(as[0] == n){ break; }
    //
    //         next.assign(n, 1);
    //         for(int j = 0; j < n; j++){
    //             for(int k = 1; k <= as[j]; k++){
    //                 if(j - k >= 0){ next[j - k]++; }
    //                 if(j + k < n){ next[j + k]++; }
    //             }
    //         }
    //         next.swap(as);
    //     }
    //     printde(as);
    // }

    vector<int> inis(n, 0);
    SegTree next(inis);
    for(int i = 0; i < k; i++){
        next.set0();
        for(int j = 0; j < n; j++){
            // next.add(max(0, j - as[j]), min(n - 1, j + as[j]), 1);
            int value = st.getVal(j);
            next.add(j - value, j + value, 1);
        }
        swap(st, next);
        // st = next;

        // for(int i = 0; i < n; i++){
        //     cout << st.getVal(i) << ' ';
        // }
        // cout << '\n';

        // if(st.getVal(0) == n){ break; }
        // if(k == 100){ break; }
        if(watch.elapsed() > 1.95){ break; }
    }
    // printde(cnt);
    for(int i = 0; i < n; i++){
        cout << st.getVal(i) << ' ';
    }
    cout << '\n';
}