The Preliminary Contest for ICPC Asia Xuzhou 2019 E. XKC's basketball team
题目链接: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的更多相关文章
- 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 题目大意:对于给定序列,求出对于每个位置求出比该数大于m的最靠右的位置. 思路:首先对序列进行离散化,然后对于每个数的下 ...
- 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); ...
随机推荐
- c# 笔试面试题01
一.抽象与接口的区别: ,抽象(abstract): ()抽象类中可以有抽象方法,也可没有: ()抽象方法包含实现,也可以由子类实现: ()抽象类不能被sealed修饰,只能使用abstract关键字 ...
- AtCoder Grand Contest 037 简要题解
从这里开始 题目目录 Problem A Dividing a String 猜想每段长度不超过2.然后dp即可. 考虑最后一个长度大于等于3的一段,如果划成$1 + 2$会和后面相同,那么划成$2 ...
- [原创]App崩溃率统计工具推荐
[原创]App崩溃率统计工具推荐 1 友盟(推荐) 友盟是一款比较成熟的工具,同时也可以展示留存,日活,事件等. 2 Bugly 腾讯的bugly统计数据也算是比较早的,可惜后续维护比较弱,功能与 ...
- 从图(Graph)到图卷积(Graph Convolution):漫谈图神经网络模型 (三)
本文属于图神经网络的系列文章,文章目录如下: 从图(Graph)到图卷积(Graph Convolution):漫谈图神经网络模型 (一) 从图(Graph)到图卷积(Graph Convolutio ...
- python 爬取媒体文件(无防火墙)
#coding = utf-8 import requests import pandas as pd import os,time root_path = './根目录/' input_file = ...
- SpringBoot 第一篇:入门篇
作者:追梦1819 原文:https://www.cnblogs.com/yanfei1819/p/10819728.html 版权声明:本文为博主原创文章,转载请附上博文链接! 前言 博主从去年 ...
- Gin框架 - 项目目录
概述 今天给大家分享,在 API 端使用 Gin 框架时,项目的目录. 目录 ├─ Project Name │ ├─ config //配置文件 │ ├── ... │ ├─ controller ...
- 集合类源码(六)Map(HashMap, Hashtable, LinkedHashMap, WeakHashMap)
HashMap 内部结构 内部是一个Node数组,每个Node都是链表的头,当链表的大小达到8之后链表转变成红黑树. put操作 final V putVal(int hash, K key, V v ...
- ext.net 这两个id不是同一个对象,小心!
今天遇到了一个很奇怪的问题,查到最后发现是下面代码原因 代码中使用store存储js对象 mcp_liststore.data.items[3].id mcp_liststore.data.get(3 ...
- NFS客户端挂载失败之authenticated unmount request from
1.故障现象 客户端挂载时夯住,无反应,无报错,如下图: 2.故障前对挂载目录的操作 发现故障前挂载目录被误删除,后通过备份分为恢复 3.故障排查步骤 .检查客户端及服务端防火墙规则 .检查selin ...