#include using namespace std; int main() { cin.tie(0); ios::sync_with_stdio(false); int n, d; cin >> n >> d; array, 200000> p; for (int i = 0; i < n; i++) { int a_i; cin >> a_i; p[i] = make_pair(a_i, i); } sort(p.begin(), p.begin() + n); array a, ans; int index = 0; for (int i = 0; i < n; i++) a[i] = p[i].first; for (int i = 0; i < n; i++) { index = upper_bound(a.begin() + index, a.begin() + n, a[i] - d) - a.begin(); ans[p[i].second] = index; } for (int i = 0; i < n; i++) { cout << ans[i] << "\n"; } }