[The Preliminary Contest for ICPC Asia Xuzhou 2019 - 徐州网络赛E] XKC's basketball team
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
题意
cxk 有一支 n 个人组成的篮球队伍,每个人都有一个实力值 w。当某个人的右边出现了实力值超过他至少 m 的人,那么他就会感到愤怒,且愤怒值为能够使得他愤怒的最右边的人与他之间的人数。换句话说,对于队员 i,能够使得他愤怒的人 j (j > i)的实力值 w[j] >= w[i] + m,且愤怒值为 max(j)-i-1,特别的,若没有人能够使得他愤怒,他的愤怒值就为 -1。求出所有人的愤怒值。
思路
建一个线段树,维护区间最大值。每次查询优先查找右子树(因为要求 j 的值为最大),若右子树的区间的实力值的最大值不满足愤怒的条件,再查找左子树,若都不满足,则返回 -1。
代码
#include <bits/stdc++.h>
#define ll long long
#define INF 0x3f3f3f3f
using namespace std;
const int maxn = 5e5+5;
int n, m;
int st[maxn<<2], a[maxn];void pushUp(int rt)
{st[rt] = max(st[rt<<1], st[rt<<1|1]);
}void build(int l, int r, int rt)
{if(l == r){st[rt] = a[l];return;}int m = l+((r-l)>>1);build(l, m, rt<<1);build(m+1, r, rt<<1|1);pushUp(rt);
}int query(int val, int L, int R, int l, int r, int rt)
{if(L > r || R < l || st[rt] < val)return -1;if(l == r)return l;int m = l + ((r-l)>>1);if(R > m && st[rt<<1|1] >= val)return query(val, L, R, m+1, r, rt<<1|1);if(L <= m && st[rt<<1] >= val)return query(val, L, R, l, m, rt<<1);return -1;
}void read()
{cin >> n >> m;for(int i = 1; i <= n; ++i)cin >> a[i];
}void solve()
{build(1, n, 1);int ans = 0;for(int i = 1; i <= n; ++i){ans = query(a[i]+m, i+1, n, 1, n, 1);if(~ans)ans = ans - i - 1;cout << ans;cout << ((i < n) ? ' ' : '\n');}
}int main()
{ios::sync_with_stdio(false);cin.tie(0); cout.tie(0);read();solve();return 0;
}
[The Preliminary Contest for ICPC Asia Xuzhou 2019 - 徐州网络赛E] XKC's basketball team相关推荐
- 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 mem ...
- The Preliminary Contest for ICPC Asia Xuzhou 2019
小 银 川,给大爷们AK穿了 比赛地址:https://www.jisuanke.com/contest/3005?view=challenges A.(待补) B.1e9的数据范围,一开始从 ...
- The Preliminary Contest for ICPC Asia Xuzhou 2019 - C Buy Watermelon | 读题
They want to cut the watermelon in two parts, and each part weighs two times as much as a kilogram . ...
- The Preliminary Contest for ICPC Asia Xuzhou 2019【B. so easy】(set 解法 与正解 unordered_map+并查集)
so easy 题目大意 给你两个操作,op=1时,将那个数不可用,op=2时进行查询功能 找到从x开始第一个存在的数 非官方题解 set 内置红黑树,有默认从小到大排序功能,所以我们可以暴力一发,不 ...
- The Preliminary Contest for ICPC Asia Nanjing 2019ICPC南京网络赛
B.super_log (欧拉降幂) •题意 定一个一个运算log*,迭代表达式为 给定一个a,b计算直到迭代结果>=b时,最小的x,输出对m取余后的值 •思路 $log*_{a}(a^{a}) ...
- The Preliminary Contest for ICPC Asia Nanjing 2019 B. super_log (广义欧拉降幂)
In Complexity theory, some functions are nearly O(1)O(1), but it is greater then O(1)O(1). For examp ...
- H. Holy Grail(The Preliminary Contest for ICPC Asia Nanjing 2019题解)
题目链接 As the current heir of a wizarding family with a long history,unfortunately, you find yourself ...
- The Preliminary Contest for ICPC Asia Shanghai 2019 B. Light bulbs(卡了线段树空间的思维题)
传送门:https://nanti.jisuanke.com/t/41399 题目描述 There are NNN light bulbs indexed from 000 to N−1N−1N−1. ...
- The Preliminary Contest for ICPC Asia Shanghai 2019 Light bulbs
https://nanti.jisuanke.com/t/41399 离散差分 #include <iostream> #include <cstring> #include ...
最新文章
- mac下Android studio配置gradle的路径
- 信息抽取(一)机器阅读理解——样本数据处理与Baseline模型搭建训练(2020语言与智能技术竞赛)
- 为什么铺天盖地都是Python的广告,它真的是无所不能吗?
- Java 绘制艺术图案
- Pycharm如何调整代码颜色以及字体样式
- AMQ学习笔记 - 16. 确认机制的测试
- Docker日志自动化: ElasticSearch、Logstash、Kibana以及Logspout
- C++ string append方法的常用用法
- 【云计算学习教程】云计算终端技术详解
- Axure share APP使用教程——如何在手机上演示axure文件
- 高仿TIMI页面易语言源码-已对接易游网络验证
- 龙芯2k1000-pmon(5)- pmon无法修改环境变量的问题
- oracle数据库三大日志,Oracle 数据库日志和用户日志位置
- Linux下笔记本电源管理
- ci框架 反向代理配置_docker-compose配置Nginx反向代理禅道
- 港科夜闻|广州市市长郭永航先生与香港科大校董会廖长城先生一行举行座谈交流...
- 绿色荧光标记麦胚凝集素(FITC-WGA)
- 自然语音处理(NLP)系列(三)——什么是序列标注?
- [网络安全技术文章之其一] 给数据科学家的十条数据安全建议
- 中小企业管理信息化的一些事(一)