题目链接:https://nanti.jisuanke.com/t/41387

思路:我们需要从后往前维护一个递增的序列。

因为:我们要的是wi + m <= wj,j要取最大,即离i最远的那个j,每次索引一个wi都需要判断下是不是大于w(i+1),完成递增序列的维护。

代码里面能更好的理解为什么要维护一个递增的序列


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <stack>
#include <string>
#include <map>
#include <cmath>
using namespace std; typedef long long LL;
#define inf 1e9
#define rep(i,j,k) for(int i = (j); i <= (k); ++i)
#define rep__(i,j,k) for(int i = (j); i < (k); ++i)
#define per(i,j,k) for(int i = (j); i >= (k); --i)
#define per__(i,j,k) for(int i = (j); i > (k); --i) const int N = (int)5e5 + ;
int arr[N];
int ans[N]; struct node{
int index;
int w; void set(int x,int y){
index = x;
w = y;
}
}que[N]; int main(){ int n,m;
scanf("%d%d",&n,&m);
rep(i,,n) scanf("%d",arr+i); int l,r,mid,A;
int len = ;
//最后一个先处理
que[++len].set(n,arr[n]);
ans[n] = -;
//
per(i,n-,){ //比之前的都大
if(arr[i] + m > que[len].w){
ans[i] = -;
if(arr[i] > que[len].w)
que[++len].set(i,arr[i]);
}
//比第一个还小
else if(arr[i] + m <= que[].w){
ans[i] = que[].index - i -;
// printf("this is %d test ans is %d \n",i,ans[i]);
}
//在中间有答案
else{
l = ;
r = len;
while(l <= r){
mid = (l + r) >> ;
if(arr[i] + m <= que[mid].w){
A = que[mid].index;
r = mid - ;
}
else l = mid + ;
}
// printf("arr[%d] = index %d - index %d - 1\n",i,A,i);
ans[i] = A - i -;
}
} // rep(i,1,ll) printf("%d ",que[i].index);
// printf("\n"); printf("%d",ans[]);
rep(i,,n) printf(" %d",ans[i]);
printf("\n"); getchar(); getchar();
return ;
}

The Preliminary Contest for ICPC Asia Xuzhou 2019 E. XKC's basketball team的更多相关文章

  1. 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 ...

  2. The Preliminary Contest for ICPC Asia Xuzhou 2019 E. XKC's basketball team (线段树)

    题目链接:https://nanti.jisuanke.com/t/41387 题目大意:对于给定序列,求出对于每个位置求出比该数大于m的最靠右的位置. 思路:首先对序列进行离散化,然后对于每个数的下 ...

  3. The Preliminary Contest for ICPC Asia Xuzhou 2019 E XKC's basketball team(排序+二分)

    这题其实就是瞎搞,稍微想一想改一改就能过. 排序按值的大小排序,之后从后向前更新node节点的loc值,如果后一个节点的loc大于(不会等于)前一个节点的loc,就把前一个节点的loc值设置为后面的l ...

  4. 计蒜客 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 ...

  5. The Preliminary Contest for ICPC Asia Xuzhou 2019

    A:Who is better? 题目链接:https://nanti.jisuanke.com/t/41383 题意: 类似于有N个石子,先手第一次不能拿完,每次后手只能拿 1 到 前一次拿的数量* ...

  6. 计蒜客 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 ...

  7. The Preliminary Contest for ICPC Asia Xuzhou 2019 【 题目:so easy】{并查集维护一个数的下一个没有被删掉的数} 补题ING

    题意:给[1,n],n个数,有两种操作: 1 x,删去x2 x,查询还未被删去的数中大于等于x的最小的数是多少. input: output: 做法:按照并查集的方法压缩路径 代码: #include ...

  8. 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 ...

  9. 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); ...

随机推荐

  1. DVWA File Inclusion 通关教程

    File Inclusion 介绍File Inclusion,即文件包含(漏洞),是指当服务器开启allow_url_include选项时,就可以通过php的某些特性函数:include(),req ...

  2. vagrant 共享本地目录

    安装nfs插件 vagrant plugin install vagrant-winnfsd 打开windows上的vagrantfile 修改如下: Vagrant.configure(" ...

  3. python 利用淘宝IP库 查询IP归属地

    #coding:utf-8 from django.test import TestCase import json import urllib ip = "114.114.114.114& ...

  4. [转载]3.5 UiPath对剪切板的介绍和使用

    一.剪切板操作的介绍 模拟用户使用剪切板操作的一种行为: 例如使用设置剪切板(SettoClipboard),从剪切板获取(GetfromClipboard)的操作 二.剪切板相关操作在UiPath中 ...

  5. SpringCloud项目中使用Nacos作为注册中心

    SpringCloud和Nacos的介绍原理在这里就不多说了,百度一大堆,这里就只是记录一下刚开始学习时候项目的使用过程 Nacos-server 我这里是从官网下载的Nacos-server 下载地 ...

  6. JVM学习笔记1

    1.运行时数据结构 2.堆分代 3.垃圾收集器 Parallel Scavenge收集器:新生代称为PSYoungGen,老年代称为ParOldGen,永久代称为Metaspace ParNew收集器 ...

  7. 【阿里云IoT+YF3300】2.阿里云IoT云端通信Alink协议介绍

    如果单单只有MQTT协议,也许很难支撑起阿里这个IoT大厦.Alink协议的出现,不仅仅是数据从传感端搬到云端,它就如基因图谱,它勾画了一个大厦的骨架,有了它,才有了IoT Studio,才有了大数据 ...

  8. Spring AOP环绕异常影响的报错

    最近遇到一个问题,异常是: java.lang.ClassCastException: org.springframework.http.ResponseEntity cannot be cast t ...

  9. eclipse使用maven,启动工程tomcat报错:java.lang.ClassNotFoundException: org.springframework.web.context.Contex

    maven是个不错的管理jar包工具,但是我们在eclipse使用maven时,总是遇上这样那样的问题,比如今天,我编译工程,启动过后,tomcat报错:java.lang.ClassNotFound ...

  10. NoSQL之redis用法

    什么是NoSQL? 泛指非关系型的数据库 不支持SQL语法 存储结构跟传统关系型数据库中的那种关系表完全不同,nosql中存储的数据都是Key-Value(即键值对关系)形式 NoSQL的世界中没有一 ...