前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >The Preliminary Contest for ICPC Asia Xuzhou 2019 徐州网络赛 XKC's basketball team

The Preliminary Contest for ICPC Asia Xuzhou 2019 徐州网络赛 XKC's basketball team

作者头像
风骨散人Chiam
发布2020-10-28 10:15:23
2950
发布2020-10-28 10:15:23
举报
文章被收录于专栏:CSDN旧文

XKC , the captain of the basketball team , is directing a train of nn team members. He makes all members stand in a row , and numbers them 1 \cdots n1⋯n from left to right.

The ability of the ii-th person is w_iwi​ , and if there is a guy whose ability is not less than w_i+mwi​+m stands on his right , he will become angry. It means that the jj-th person will make the ii-th person angry if j>ij>i and w_j \ge w_i+mwj​≥wi​+m.

We define the anger of the ii-th person as the number of people between him and the person , who makes him angry and the distance from him is the longest in those people. If there is no one who makes him angry , his anger is -1−1 .

Please calculate the anger of every team member .

Input

The first line contains two integers nn and m(2\leq n\leq 5*10^5, 0\leq m \leq 10^9)m(2≤n≤5∗105,0≤m≤109) .

The following  line contain nn integers w_1..w_n(0\leq w_i \leq 10^9)w1​..wn​(0≤wi​≤109) .

Output

A row of nn integers separated by spaces , representing the anger of every member .

样例输入复制

代码语言:javascript
复制
6 1
3 4 5 6 2 10

样例输出复制

代码语言:javascript
复制
4 3 2 1 0 -1

队友做的,没大有思路。

代码语言:javascript
复制
#include<cstdio>
#include<vector>
#include<queue>
#include<cmath>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
#define LL long long
#define MAXN 500100
struct node
{
    LL x;
    LL y;
} a[MAXN*2];
LL b[MAXN],c[MAXN];
bool cmp(node u,node v)
{

    return u.x<v.x;
}
int main()
{
    LL n,m,i,j;
    scanf("%lld%lld",&n,&m);
    for(i=1; i<=n; i++)
    {
        scanf("%lld",&a[i].x);
        a[i].y=i;
        b[i]=a[i].x;
    }
    j=n;
    sort(a+1,a+n+1,cmp);
    bool flag=false;
    for(i=1; i<=n; i++)
    {
        while(b[j]<a[i].x+m)
        {
            if(j==0)
            {
                flag=true;
                break;
            }
            j--;
        }
        if(flag)
            c[a[i].y]=-1;
        else{
            if(j<=a[i].y) c[a[i].y]=-1;
        else
            c[a[i].y]=j-a[i].y-1;
            }
    }
    for(i=1; i<n; i++)
        printf("%lld ",c[i]);
    printf("%lld",c[n]);
    return 0;
}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2019/09/07 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • Input
  • Output
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档