#include #include struct Element{ int v; int id; bool operator < (const Element &other)const{ return v= 1; i--){ while(p>=1 && a[p].v>a[i].v-d) p--; ans[a[i].id] = p; } for(int i = 1; i <= n; i++) printf("%d\n",ans[i]); return 0; }