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\). 题解:从后向前维护一个递增的队列,从后 ...
随机推荐
- MessagePack Java Jackson Dataformat - POJO 的序列化和反序列化
在本测试代码中,我们定义了一个 POJO 类,名字为 MessageData,你可以访问下面的链接找到有关这个类的定义. https://github.com/cwiki-us-demo/serial ...
- poj 3190 贪心+优先队列优化
Stall Reservations Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4274 Accepted: 153 ...
- Dungeon Master (POJ - 2251)(BFS)
转载请注明出处: 作者:Mercury_Lc 地址:https://blog.csdn.net/Mercury_Lc/article/details/82693907 题目链接 题解:三维的bfs,一 ...
- mac使用sublime text3打开当前文件夹的终端
打开sublime text3,同时按住shift+command+p打开扩展列表, 选择Package Control: Install Pageage,回车. 在输入框输入: terminal,回 ...
- CentOS7下安装mysql5.1 或升级到5.7 以及小问题的解决方案
正文开始 1.首先打开终端输入以下内容下载mysql5.1的repo源(安装5.7从第二步执行) wget http://repo.mysql.com/mysql-community-release ...
- git忽略提交:.gitignore
在使用Git的过程中,我们喜欢有的文件比如日志,临时文件,编译的中间文件等不要提交到代码仓库,这时就要设置相应的忽略规则,来忽略这些文件的提交. Git 忽略文件提交的方法 有三种方法可以实现忽略Gi ...
- vue——父组件调用子组件
<template> <div> child1 </div> </template> <script> export default { n ...
- HTML页面间传值
页面一: window.location="./showUserMsg.html?IDno="+IDno+"&&thedate="+thedat ...
- 如何在GitHub上下载一部分文件(单个文件夹)
Preface Github下的项目可能很大,里面有很多的子文件夹,我们可能只需要使用某个子目录下的资源,可以不用下载完整的repo就能使用. 例如,我想下载这个repo中的mnist_gan文件:h ...
- PHP中获取当前页面的完整URL、PHP URL处理、获取不带扩展名的文件名
javascript实现: top.location.href 顶级窗口的地址this.location.href 当前窗口的地址 PHP实现 #测试网址: http://localhost/blog ...