The Preliminary Contest for ICPC Asia Xuzhou 2019 E. XKC's basketball team (线段树)
题目链接:https://nanti.jisuanke.com/t/41387
题目大意:对于给定序列,求出对于每个位置求出比该数大于m的最靠右的位置。
思路:首先对序列进行离散化,然后对于每个数的下标更新到线段树上,然后对于每个位置的数考虑,二分查找比该数大于m的第一个位置到最右端,查找下标的最大值即可。
代码:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e6+;
int n,m;
int w[maxn],x[maxn],Max[maxn<<],ans[maxn];
void pushup(int rt){Max[rt]=max(Max[rt<<],Max[rt<<|]);}
void update(int pos,int val,int l,int r,int rt){
if(l==r){
Max[rt]=val;
return;
}
int mid=(l+r)>>;
if(pos<=mid) update(pos,val,l,mid,rt<<);
else update(pos,val,mid+,r,rt<<|);
pushup(rt);
}
int query(int L,int R,int l,int r,int rt){
if(L<=l&&R>=r){
return Max[rt];
}
int ans=,mid=(l+r)>>;
if(mid>=L) ans=max(ans,query(L,R,l,mid,rt<<));
if(mid<=R) ans=max(ans,query(L,R,mid+,r,rt<<|));
return ans;
} int main(){
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++) {
scanf("%d",&w[i]);
x[i]=w[i];
}
sort(x+,x+n+);
int len=unique(x+,x++n)-x-;
for(int i=;i<=n;i++){
int pos=lower_bound(x+,x++len,w[i])-x;
update(pos,i,,len,);
}
for(int i=;i<=n;i++){
int pos=lower_bound(x+,x++len,w[i]+m)-x;
ans[i]=query(pos,len,,len,)-i-;;
if(ans[i]<)ans[i]=-;
}
printf("%d",ans[]);
for(int i=;i<=n;i++)
printf(" %d",ans[i]);
printf("\n");
return ;
}
The Preliminary Contest for ICPC Asia Xuzhou 2019 E. XKC's basketball team (线段树)的更多相关文章
- 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 E. XKC's basketball team
题目链接:https://nanti.jisuanke.com/t/41387 思路:我们需要从后往前维护一个递增的序列. 因为:我们要的是wi + m <= wj,j要取最大,即离i最远的那个 ...
- The Preliminary Contest for ICPC Asia Xuzhou 2019 E XKC's basketball team(排序+二分)
这题其实就是瞎搞,稍微想一想改一改就能过. 排序按值的大小排序,之后从后向前更新node节点的loc值,如果后一个节点的loc大于(不会等于)前一个节点的loc,就把前一个节点的loc值设置为后面的l ...
- 计蒜客 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
A:Who is better? 题目链接:https://nanti.jisuanke.com/t/41383 题意: 类似于有N个石子,先手第一次不能拿完,每次后手只能拿 1 到 前一次拿的数量* ...
- 计蒜客 41387.XKC's basketball team-线段树(区间查找大于等于x的最靠右的位置) (The Preliminary Contest for ICPC Asia Xuzhou 2019 E.) 2019年徐州网络赛
XKC's basketball team XKC , the captain of the basketball team , is directing a train of nn team mem ...
- The Preliminary Contest for ICPC Asia Xuzhou 2019 【 题目:so easy】{并查集维护一个数的下一个没有被删掉的数} 补题ING
题意:给[1,n],n个数,有两种操作: 1 x,删去x2 x,查询还未被删去的数中大于等于x的最小的数是多少. input: output: 做法:按照并查集的方法压缩路径 代码: #include ...
- G.Colorful String(The Preliminary Contest for ICPC Asia Xuzhou 2019)
https://nanti.jisuanke.com/t/4 #include <bits/stdc++.h> using namespace std; ,; typedef unsign ...
- E.XKC's basketball team(The Preliminary Contest for ICPC Asia Xuzhou 2019)
https://nanti.jisuanke.com/t/41387 解: 离散化+线段树. #define IOS ios_base::sync_with_stdio(0); cin.tie(0); ...
随机推荐
- 获取免费的https证书
可以通过网站获取免费的https证书 首先到https://freessl.org注册一个账号 然后就可以开始创建免费证书了 获取的证书里面通常只有pem后缀文件 nodejs使用的时候需要crt文件 ...
- webpack安装低于4版本(没有配置webpack.config.js)
webpack安装低于4版本(没有配置webpack.config.js) webpack 无需配置输出参数-o 低版本 1.初始化项目 npm init -y 初始化项目 2.安装webpack@ ...
- orm练习题
表关系图 models.py from django.db import models # Create your models here. class Teacher(models.Model): ...
- WPF使用BindingListCollectionView 和 ListCollectionView 视图排序集合
当将一个集合或DataTable绑定到ItemsControl控件时,在后对台会自动地创建数据视图,这个视图位于数据源和绑定的控件之间,数据视图是进行数据源的窗口.它跟踪当前项,并且提供各种功能,如排 ...
- flutter dialog异常Another exception was thrown: Navigator operation requested with a context that does not include a Navigator
我在使用flutter里的对话框控件的时候遇到了一个奇怪的错误 Another exception was thrown: Navigator operation requested with a c ...
- 【EWM系列】SAP EWM中仓库任务WT创建的函数
公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[EWM系列]SAP EWM中仓库任务WT创建的 ...
- Python基础语法之常量与变量
一.变量的命名规则 只能以下划线,数字和字母组成,不可以是特殊字符: 不可以以数字开头: 关键字不可作为变量名: 变量名区分大小写: 要具有描述性: 二.常量 python中并没有关键字const,在 ...
- docker--docker仓库
8 docker仓库 Docker仓库(Repository)类似与代码仓库,是Docker集中存放镜像文件的地方. 8.1 docker hub 1.打开https://hub.docker.com ...
- laravel框架之增刪改查
<?php namespace App\Http\Controllers\admin; use Illuminate\Http\Request as request; use App\Http\ ...
- Python入门之 Python内置函数
Python入门之 Python内置函数 函数就是以功能为导向,一个函数封装一个功能,那么Python将一些常用的功能(比如len)给我们封装成了一个一个的函数,供我们使用,他们不仅效率高(底层都是用 ...