#include <bits/stdc++.h>
using namespace std;
const int inf = (int)1e9;
const int mod = inf + 7;
const double eps = 1e-9;
const double pi = acos(-1.0);
struct tree {
  int mn, cnt, add;
} t[400400];
int dp[100100], n, k, a[100100];
vector<int> g[100100];
void push(int v, int tl, int tr) {
  if (t[v].add != 0) {
    if (tl == tr) {
      t[v].mn += t[v].add;
      t[v].add = 0;
    } else {
      t[v + v].add += t[v].add;
      t[v + v + 1].add += t[v].add;
      t[v].mn += t[v].add;
      t[v].add = 0;
    }
  }
}
tree merge(tree a, tree b) {
  tree c;
  c.add = 0;
  c.mn = min(a.mn + a.add, b.mn + b.add);
  c.cnt = 0;
  if (a.mn + a.add == c.mn) c.cnt += a.cnt;
  if (b.mn + b.add == c.mn) c.cnt += b.cnt;
  return c;
}
void build(int v, int tl, int tr) {
  if (tl == tr) {
    t[v].mn = 0;
    t[v].cnt = 1;
    return;
  }
  int mid = (tl + tr) >> 1;
  build(v + v, tl, mid);
  build(v + v + 1, mid + 1, tr);
  t[v] = merge(t[v + v], t[v + v + 1]);
}
pair<int, int> get(int v, int tl, int tr, int l, int r) {
  push(v, tl, tr);
  if (r < tl || l > tr) return make_pair(inf, 0);
  if (l <= tl && tr <= r) return make_pair(t[v].mn, t[v].cnt);
  int mid = (tl + tr) >> 1;
  pair<int, int> a = get(v + v, tl, mid, l, r);
  pair<int, int> b = get(v + v + 1, mid + 1, tr, l, r);
  if (a.first != b.first) return min(a, b);
  return make_pair(a.first, a.second + b.second);
}
void update(int v, int tl, int tr, int l, int r, int val) {
  push(v, tl, tr);
  if (r < tl || l > tr) return;
  if (l <= tl && tr <= r) {
    t[v].add += val;
    return;
  }
  int mid = (tl + tr) >> 1;
  update(v + v, tl, mid, l, r, val);
  update(v + v + 1, mid + 1, tr, l, r, val);
  t[v] = merge(t[v + v], t[v + v + 1]);
}
int calc() {
  pair<int, int> a = get(1, 1, n, 1, n);
  if (a.first == 0) return n - a.second;
  return n;
}
void dfs(int v) {
  int l = max(v - k, 1), r = min(v + k, n);
  update(1, 1, n, l, r, 1);
  dp[v] = calc();
  for (int i = 0; i < g[v].size(); ++i) {
    int to = g[v][i];
    dfs(to);
  }
  update(1, 1, n, l, r, -1);
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  cin >> n >> k;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    g[a[i]].push_back(i);
  }
  build(1, 1, n);
  for (int i = 0; i < (int)g[0].size(); ++i) {
    dfs(g[0][i]);
  }
  for (int i = 1; i <= n; ++i) {
    cout << dp[i] << " ";
  }
  cout << endl;
}
