The Preliminary Contest for ICPC Asia Xuzhou 2019 徐州网络赛 XKC's basketball team
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 .
样例输入复制
6 1
3 4 5 6 2 10
样例输出复制
4 3 2 1 0 -1
队友做的,没大有思路。
#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;
}
The Preliminary Contest for ICPC Asia Xuzhou 2019 徐州网络赛 XKC's basketball team的更多相关文章
- The Preliminary Contest for ICPC Asia Xuzhou 2019 徐州网络赛 K题 center
You are given a point set with nn points on the 2D-plane, your task is to find the smallest number o ...
- The Preliminary Contest for ICPC Asia Xuzhou 2019 徐州网络赛 D Carneginon
Carneginon was a chic bard. But when he was young, he was frivolous and had joined many gangs. Recen ...
- The Preliminary Contest for ICPC Asia Xuzhou 2019 徐州网络赛 C Buy Watermelon
The hot summer came so quickly that Xiaoming and Xiaohong decided to buy a big and sweet watermelon. ...
- The Preliminary Contest for ICPC Asia Xuzhou 2019 徐州网络赛 B so easy
题目链接:https://nanti.jisuanke.com/t/41384 这题暴力能过,我用的是并查集的思想,这个题的数据是为暴力设置的,所以暴力挺快的,但是当他转移的点多了之后,我觉得还是我这 ...
- The Preliminary Contest for ICPC Asia Xuzhou 2019 徐州网络赛 A Who is better?
A After Asgard was destroyed, tanker brought his soldiers to earth, and at the same time took on the ...
- 计蒜客 41391.query-二维偏序+树状数组(预处理出来满足情况的gcd) (The Preliminary Contest for ICPC Asia Xuzhou 2019 I.) 2019年徐州网络赛)
query Given a permutation pp of length nn, you are asked to answer mm queries, each query can be rep ...
- The Preliminary Contest for ICPC Asia Xuzhou 2019 E XKC's basketball team [单调栈上二分]
也许更好的阅读体验 \(\mathcal{Description}\) 给n个数,与一个数m,求\(a_i\)右边最后一个至少比\(a_i\)大\(m\)的数与这个数之间有多少个数 \(2\leq n ...
- The Preliminary Contest for ICPC Asia Xuzhou 2019
A:Who is better? 题目链接:https://nanti.jisuanke.com/t/41383 题意: 类似于有N个石子,先手第一次不能拿完,每次后手只能拿 1 到 前一次拿的数量* ...
- The Preliminary Contest for ICPC Asia Xuzhou 2019 E. XKC's basketball team
题目链接:https://nanti.jisuanke.com/t/41387 思路:我们需要从后往前维护一个递增的序列. 因为:我们要的是wi + m <= wj,j要取最大,即离i最远的那个 ...
随机推荐
- MTK Android Camera运行流程
Android Camera 运行流程 总体架构1.CameraService服务的注册2.Client端的应用层到JNI层Camera App-JNI3.Client到Service的连接4.HAL ...
- javascript 入门 之select2获取远程数据
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"/> <meta lan ...
- buuctf misc wp 02
buuctf misc wp 02 7.LSB 8.乌镇峰会种图 9.rar 10.qr 11.ningen 12.文件中的秘密 13.wireshark 14.镜子里面的世界 15.小明的保险箱 1 ...
- 【DataBase】 在Windows系统环境 下载和安装 解压版MySQL数据库
MySQL官网解压版下载地址:https://dev.mysql.com/downloads/mysql/ 为什么不推荐使用安装版?无脑下一步,很多配置的东西学习不到了 点选第一个就好了,下面的是调试 ...
- tensorflow2.x 报错 Could not load dynamic library 'cudart64_101.dll'
当我们使用 tensorflow 最新版本的时候 ,会出现这样的错误 -- ::] Could not load dynamic library 'cudart64_101.dll'; dlerror ...
- 用python爬取之后发现果然如此,都说知乎的小姐姐漂亮
前言 文的文字及图片来源于网络,仅供学习.交流使用,不具有任何商业用途,版权归原作者所有,如有问题请及时联系我们以作处理. PS:如有需要Python学习资料的小伙伴可以加点击下方链接自行获取http ...
- Pytorch实现MNIST手写数字识别
Pytorch是热门的深度学习框架之一,通过经典的MNIST 数据集进行快速的pytorch入门. 导入库 from torchvision.datasets import MNIST from to ...
- RocketMQ存储机制与确认重传机制
引子 消息队列之前就听说过,但一直没有学习和接触,直到最近的工作流引擎项目用到,需要了解学习一下.本文主要从一个初学者的角度针对RocketMQ的存储机制和确认重传机制做一个浅显的总结. 存储机制 我 ...
- TensorFlow命令行参数FLAGS使用
import os os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2' import tensorflow as tf #tensorboard --logdir=&qu ...
- coding++:@DisallowConcurrentExecution 注解的作用
Quartz定时任务默认都是并发执行的,不会等待上一次任务执行完毕,只要间隔时间到就会执行, 如果定时任执行太长,会长时间占用资源,导致其它任务堵塞. 在Spring中这时需要设置concurrent ...