#include <bits/stdc++.h>
using namespace std;
const long long N = 5e5 + 2;
const long long Mod = 1e9 + 7;
const long long INF = 2e9 + 1;
int n, k;
vector<long long> G[N];
int ans[N];
void DFS(int u, int sum, int last) {
  sum += min(u + k, n) - max(u - k - 1, last);
  ans[u] = sum;
  last = min(n, u + k);
  for (int v : G[u]) DFS(v, sum, last);
}
int a[N];
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    a[i] = x;
    if (x) G[x].push_back(i);
  }
  for (int i = 1; i <= n; i++)
    if (!a[i]) DFS(i, 0, 0);
  for (int i = 1; i <= n; i++) cout << ans[i] << ' ';
  cout << endl;
  return 0;
}
