#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5;
const int inf = 1e9 + 1;
const long double eps = 1e-8;
const int Q = 1e9 + 7;
vector<int> g[MAXN];
bool mark[MAXN];
int ans[MAXN];
set<int> s;
int n, k;
void dfs(int v, int res) {
  if (mark[v]) return;
  mark[v] = true;
  auto lb = s.lower_bound(v);
  if (lb != s.begin()) lb--;
  auto rb = s.upper_bound(v);
  int left, right;
  if (lb != s.end())
    left = max(*lb + k + 1, v - k);
  else
    left = max(0, v - k);
  if (rb != s.end())
    right = min(*rb - k - 1, v + k);
  else
    right = min(n - 1, v + k);
  ans[v] = res + max(0, right - left + 1);
  s.insert(v);
  for (int i = 0; i < g[v].size(); i++) dfs(g[v][i], ans[v]);
  s.erase(v);
}
int main() {
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    if (x > 0) g[x - 1].push_back(i);
  }
  for (int i = 0; i < n; i++) dfs(i, 0);
  for (int i = 0; i < n; i++) cout << ans[i] << ' ';
  return 0;
}
