The Preliminary Contest for ICPC Asia Xuzhou 2019 B so easy

本文介绍了一种算法,用于计算篮球队伍中成员的愤怒值。每个成员的能力不同,若右侧有人能力超过其m点,则会生气。算法通过并查集或set实现,计算每个人与使其生气者间的距离。

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

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

We define the anger of the iii-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−1 .

Please calculate the anger of every team member .

Input

The first line contains two integers nnn and m(2≤n≤5∗105,0≤m≤109)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 nnn integers w1..wn(0≤wi≤109)w_1..w_n(0\leq w_i \leq 10^9)w1​..wn​(0≤wi​≤109) .

Output

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

样例输入

6 1
3 4 5 6 2 10

样例输出

4 3 2 1 0 -1

 

思路:并查集,一个数被标记后,看它相邻两个数有没有被标记的,有的话,把他和相邻被标记的数合并,两个数合并的话,谁大谁做父亲,查询的时候,如果查询的数没被标记,直接输出他的父亲+1

(这题set也能水过。。。。。。

#include<stdio.h>
#include<math.h>
#include<vector>
#include<cstring>
#include<queue>
#include<iostream>
#include<algorithm>
#define maxn 550000
using namespace std;
#include <unordered_map>
#include<map>
int a[maxn],ans[maxn];
struct node
{
    int id,num;
     friend bool operator <(node n1,node n2)
    {
        return n1.num>n2.num;//从小到大
    }
}b[maxn];
int main()
{
    int n,m;
    memset(ans,-1,sizeof(ans));
    priority_queue<node>que;
    scanf("%d %d",&n,&m);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
        b[i].id=i;
        b[i].num=a[i];
        que.push(b[i]);
    }
    for(int i=n;i>=1;i--)
    {
        while(!que.empty())
        {

            node st=que.top();
            //printf("i=%d id=%d num=%d\n",i,st.id,st.num);
            if(st.id>=i) {que.pop();continue;}
            if(st.num>a[i]-m) break;
            ans[st.id]=i-st.id-1;
            //printf("ans[%d]=%d\n",st.id,ans[st.id]);
            que.pop();
        }
    }
    for(int i=1;i<=n;i++)
    {
        //if(ans[i]==0) ans[i]=-1;
        if(i==n)
        {
            printf("%d\n",ans[i]);
        }
        else printf("%d ",ans[i]);
    }
}

 

Sure, I'd be happy to give you some ideas for organizing a speech contest. Here are some suggestions: 1. Determine the theme and rules: Decide on the theme of the contest and the rules for participants. Will it be an open topic, or will there be a specific theme? What is the maximum length of the speech? Will there be any specific guidelines for language or content? 2. Decide on the judging criteria: Determine how the speeches will be evaluated. Will judges be looking for content, delivery, or both? Will there be a score sheet or rubric that judges will use to score the speeches? 3. Recruit judges: Find people who are qualified to judge the speeches. Ideally, they should have experience in public speaking or have a background in the theme of the contest. 4. Promote the contest: Advertise the contest to potential participants, such as students, professionals, or members of a specific community. Use social media, flyers, and other methods to get the word out. 5. Registration and selection: Set a deadline for registration and selection of participants. Consider having a preliminary round to narrow down the field before the final competition. 6. Prepare the venue: Ensure that the venue is suitable for the contest. Make sure that there is adequate seating, sound equipment, and lighting for the speakers. 7. Hold the contest: Set a date and time for the contest, and make sure that all participants and judges are aware of the schedule. Encourage audience participation and provide refreshments. 8. Award ceremony: After the contest, hold an award ceremony to recognize the winners and participants. Provide certificates or other prizes to the top performers. I hope these ideas help you in organizing a successful speech contest!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值