2019 徐州icpc网络赛 E. XKC's basketball team
题库链接:
https://nanti.jisuanke.com/t/41387
题目大意
给定n个数,与一个数m,求ai右边最后一个至少比ai大m的数与这个数之间有多少个数
思路
对于每一个数,利用二分的方法求他右边大于等于ai+m的数的最后一个值。
关键在于怎么二分呢?
利用线段树存储区间最大值,看这个区间的最大值是不是比ai+m大
代码:
#include<bits/stdc++.h>
using namespace std;
#define maxn 1000005
#define mod 1000000007
int a[maxn];
struct node
{
int l,r,ma;
}tree[maxn*];
void build(int l,int r,int p)
{
tree[p].l = l;
tree[p].r = r;
tree[p].ma = -;
if(l == r)
{
tree[p].ma = a[l];
return;
}
int mid = (l+r)/;
build(l,mid,p*);
build(mid+,r,p*+);
tree[p].ma = max(tree[p*].ma,tree[p*+].ma);
}
int query(int x,int y,int p)
{
if(x == tree[p].l && y == tree[p].r)
return tree[p].ma;
int mid = (tree[p].l + tree[p].r)/;
if(x > mid)
return query(x,y,p*+);
else if(y <= mid)
return query(x,y,p*);
else
return max(query(x,mid,p*),query(mid+,y,p*+)); }
int main()
{
int T,i,j,k,n,q,x,y,m,s,l,r,mid;
scanf("%d%d",&n,&m);
for(i=;i<=n;++i)
scanf("%d",&a[i]);
build(,n,);
for(i=;i<n;i++)
{
s=m+a[i];
l=i+;
r=n;
while(l<r)
{
mid=(l+r+)/;
if(query(mid,r,)>=s)
{
l=mid;
}
else if(query(l,mid,)>=s)
{
r=mid-;
}
else
{
break;
}
}
if(a[l]>=s)
cout<<l-i-<<' ';
else
cout<<"-1"<<' ';
}
cout<<"-1"<<endl;
return ;
}
2019 徐州icpc网络赛 E. XKC's basketball team的更多相关文章
- 2019 ICPC徐州网络赛 E. XKC's basketball team(二分)
计蒜客题目链接:https://nanti.jisuanke.com/t/41387 题目大意:给定一组无序序列,从第一个数开始,求最远比这个数大m的数,与这个数之间相隔多少数字?如果没有输出-1,否 ...
- Ryuji doesn't want to study 2018徐州icpc网络赛 树状数组
Ryuji is not a good student, and he doesn't want to study. But there are n books he should learn, ea ...
- Trace 2018徐州icpc网络赛 (二分)(树状数组)
Trace There's a beach in the first quadrant. And from time to time, there are sea waves. A wave ( xx ...
- Trace 2018徐州icpc网络赛 思维+二分
There's a beach in the first quadrant. And from time to time, there are sea waves. A wave ( xx , yy) ...
- Features Track 2018徐州icpc网络赛 思维
Morgana is learning computer vision, and he likes cats, too. One day he wants to find the cat moveme ...
- 2019沈阳icpc网络赛H德州扑克
题面:https://nanti.jisuanke.com/t/41408 题意:A,2,3,4,5,6,7,8,9,10,J,Q,K,13张牌,无花色之分,val为1~13. 给n个人名+n个牌,输 ...
- 2019 南昌ICPC网络赛H The Nth Item
The Nth Iteam 题意:F(0)=1,F(1)=1,F(n)=3*F(n-1)+2*F(n-2) (n>=2) ,F(n) mod 998244353.给出Q跟N1,Ni=Ni-1^( ...
- ICPC 2018 徐州赛区网络赛
ACM-ICPC 2018 徐州赛区网络赛 去年博客记录过这场比赛经历:该死的水题 一年过去了,不被水题卡了,但难题也没多做几道.水平微微有点长进. D. Easy Math 题意: ...
- [单调队列]XKC's basketball team
XKC's basketball team 题意:给定一个序列,从每一个数后面比它大至少 \(m\) 的数中求出与它之间最大的距离.如果没有则为 \(-1\). 题解:从后向前维护一个递增的队列,从后 ...
随机推荐
- Python之asyncio模块的使用
asyncio模块作用:构建协程并发应用的工具 python并发的三大内置模块,简单认识: .multiprocessing:多进程并发处理 .threading模块:多线程并发处理 .asyncio ...
- What is Double 11 in China? Is it a famous festival?
"1" means single, 11th, November is quadruple single!! What a tragedy for those single you ...
- VS的快捷操作
连按两下Tab,生成代码块.修改i为n,再按一次Tab,对应位置自动改变. Ctrl+. 或者 Alt+Enter ctor 连按两下Tab,生成无返回值的构造函数(constructor func ...
- JVM(七),JVM面试小知识
七.JVM面试小知识 1.JVM三大性能调优参数 -Xms -Xmx -Xss 的含义 2.java内存模型中堆和栈的区别 3.不同JDK版本中的intern()方法的区别
- 路由器与交换机配置——交换机默认网关(实现跨网段telnet)
一.实验目的:配置一台交换机,并配置默认网关,使不同网段的主机能够远程telnet登录连接到交换机 二.实验拓扑图如下: 二.实验步骤: 1.首先给PC1主机配置ip地址和网关(gateway) -- ...
- CCPC-Wannafly & Comet OJ 夏季欢乐赛(2019)E
题面 这个题暴好啊,考了很多东西. 首先设f(x)为离终点还有x步要走的期望步数,我们可以发现 : 1.x>=k时,x可以转移到的点的下标都<x. 2.x<k时,则可能走回到x或者下 ...
- mysql时区配置
1.修改linux系统时区:ln -sf /usr/share/zoneinfo/America/Los_Angeles /etc/localtime 修改为美洲美国洛杉矶时间 2.查看mysql时区 ...
- TensorFlow使用记录 (八): 梯度修剪 和 Max-Norm Regularization
梯度修剪 梯度修剪主要避免训练梯度爆炸的问题,一般来说使用了 Batch Normalization 就不必要使用梯度修剪了,但还是有必要理解下实现的 In TensorFlow, the optim ...
- 从零开始入门 K8s | Kubernetes 调度和资源管理
作者 | 子誉 蚂蚁金服高级技术专家 关注"阿里巴巴云原生"公众号,回复关键词"入门",即可下载从零入门 K8s 系列文章 PPT. Kubernetes 调 ...
- js--BOM对象(2)
一.window对象是整个bom的核心 二.window对象的属性: history:(有关客户访问过的url信息) 方法: back() 加载 history 对象列表中的前一个URL forwar ...