https://nanti.jisuanke.com/t/41387

解:

离散化+线段树。

 #define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#include <cstdio>//sprintf islower isupper
#include <cstdlib>//malloc exit strcat itoa system("cls")
#include <iostream>//pair
#include <fstream>//freopen("C:\\Users\\13606\\Desktop\\草稿.txt","r",stdin);
#include <bitset>
#include <map>
//#include<unordered_map>
#include <vector>
#include <stack>
#include <set>
#include <string.h>//strstr substr
#include <string>
#include <time.h>//srand(((unsigned)time(NULL))); Seed n=rand()%10 - 0~9;
#include <cmath>
#include <deque>
#include <queue>//priority_queue<int, vector<int>, greater<int> > q;//less
#include <vector>//emplace_back
//#include <math.h>
//#include <windows.h>//reverse(a,a+len);// ~ ! ~ ! floor
#include <algorithm>//sort + unique : sz=unique(b+1,b+n+1)-(b+1);+nth_element(first, nth, last, compare)
using namespace std;//next_permutation(a+1,a+1+n);//prev_permutation
#define fo(a,b,c) for(register int a=b;a<=c;++a)
#define fr(a,b,c) for(register int a=b;a>=c;--a)
#define mem(a,b) memset(a,b,sizeof(a))
#define pr printf
#define sc scanf
#define ls rt<<1
#define rs rt<<1|1
typedef long long ll;
void swapp(int &a,int &b);
double fabss(double a);
int maxx(int a,int b);
int minn(int a,int b);
int Del_bit_1(int n);
int lowbit(int n);
int abss(int a);
//const long long INF=(1LL<<60);
const double E=2.718281828;
const double PI=acos(-1.0);
const int inf=(<<);
const double ESP=1e-;
const int mod=(int)1e9+;
const int N=(int)1e6+; int Max[N<<];
int ans[N];
ll a[N],ta[N],tb[N];
int LS(int n)
{
int m=;
for(int i=;i<=n;++i)
tb[++m]=ta[i];
sort(tb+,tb++m);
m=unique(tb+,tb++m)-tb-;
for(int i=;i<=n;++i)
ta[i]=lower_bound(tb+,tb++m,ta[i])-tb;
return m;
}
void up(int rt)
{
Max[rt]=max(Max[rt<<],Max[rt<<|]);
} void update_dot(int pos,int V,int l,int r,int rt)
{
if(l==r)
{
Max[rt]=max(Max[rt],V);
return;
} int mid=(l+r)>>;
if(pos<=mid)
update_dot(pos,V,l,mid,rt<<);
else
update_dot(pos,V,mid+,r,rt<<|);
up(rt);
} int Quert_max(int L,int R,int l,int r,int rt)
{
if(L<=l&&r<=R)
return Max[rt];
int mid=(l+r)>>;
int ans=;
if(L<=mid)
ans=max(ans,Quert_max(L,R,l,mid,rt<<));
if(R>mid)
ans=max(ans,Quert_max(L,R,mid+,r,rt<<|));
return ans;
} int main()
{
int n;
ll m;
sc("%d%lld",&n,&m);
for(int i=;i<=n;++i)
sc("%lld",&a[i]),ta[i]=a[i],ta[i+n]=a[i]+m;
LS(*n);
ans[n]=-;
update_dot(ta[n],n,,*n,);
for(int i=n-;i>=;--i)
{
int temp=Quert_max(ta[i+n],*n,,*n,);
int pos=temp;
if(pos<i)
ans[i]=-;
else
ans[i]=pos-i+-;
update_dot(ta[i],i,,*n,);
}
for(int i=;i<=n;++i)
pr("%d%c",ans[i],i==n?'\n':' ');
return ;
} /**************************************************************************************/ int maxx(int a,int b)
{
return a>b?a:b;
} void swapp(int &a,int &b)
{
a^=b^=a^=b;
} int lowbit(int n)
{
return n&(-n);
} int Del_bit_1(int n)
{
return n&(n-);
} int abss(int a)
{
return a>?a:-a;
} double fabss(double a)
{
return a>?a:-a;
} int minn(int a,int b)
{
return a<b?a:b;
}

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

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

  2. A.Who is better?(The Preliminary Contest for ICPC Asia Xuzhou 2019)

    https://nanti.jisuanke.com/t/41383 解: 斐波那契博弈+中国剩余定理. #include <bits/stdc++.h> using namespace ...

  3. B.super_log(The Preliminary Contest for ICPC Asia Nanjing 2019)

    同:https://www.cnblogs.com/--HPY-7m/p/11444923.html #define IOS ios_base::sync_with_stdio(0); cin.tie ...

  4. H.Holy Grail ( floyd )(The Preliminary Contest for ICPC Asia Nanjing 2019)

    题意: 给出一个有向图,再给出6条原来不存在的路径,让你在这6条路径上添加一个最小的数,使图不存在负环. 思路: 直接6遍 floyd 输出就行了. #include <bits/stdc++. ...

  5. F. Greedy Sequence(主席树区间k的后继)(The Preliminary Contest for ICPC Asia Nanjing 2019)

    题意: 查找区间k的后继. 思路: 直接主席树. #define IOS ios_base::sync_with_stdio(0); cin.tie(0); #include <cstdio&g ...

  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

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

  8. The Preliminary Contest for ICPC Asia Xuzhou 2019 徐州网络赛 XKC's basketball team

    XKC , the captain of the basketball team , is directing a train of nn team members. He makes all mem ...

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

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

随机推荐

  1. 一个轻量级的模态组件,“礼貌地”要求您的用户停止使用过时的IE浏览器

    插件github地址:https://github.com/panteng/ie-blocker 我们在做项目时,会考虑到浏览器的兼容问题,当然做,全浏览器都支持的项目我还没经历过,也不想经历,目前做 ...

  2. 记一次maxwell报错:Couldn't find table 'violation_info' in database och_evcard_data

    往常maxwell是正常跑的,但是突然今天报错: Couldn't find table 'violation_info' in database och_evcard_data 而且这个库和这个表, ...

  3. 使用Xshell链接阿里云服务

    1.下载Xshell,进入xshell官网 https://xshell.en.softonic.com/,选择免费版本进行下载,在该页面https://www.netsarang.com/zh/fr ...

  4. 网络编程udp入门

    老师布置的作业 echo4_server.c #include<stdio.h> #include<stdlib.h> #include<string.h> #in ...

  5. 数据结构之队列(Queue)

    1,队列的定义 队列:是一种先进先出的数据结构,如下图所示,现进去的数据在队列前面(front),先出队列,后进入队列的数据在后面(rear),后出队列. 队列常用操作: q=Queue() #创建队 ...

  6. [转]MySQL查询语句执行过程详解

    Mysql查询语句执行原理 数据库查询语句如何执行?语法分析:首先进行语法分析,对使用sql表示的查询进行语法分析,生成查询语法分析树.语义检查:检查sql中所涉及的对象以及是否在数据库中存在,用户是 ...

  7. LC 454. 4Sum II

    Given four lists A, B, C, D of integer values, compute how many tuples (i, j, k, l) there are such t ...

  8. 分布式存储ceph--osd故障硬盘更换(6)

    正常状态:

  9. 数学建模python matlab 编程(指派问题)

    指派授课问题 现有A.B.C.D四门课程,需由甲.乙.丙.丁四人讲授,并且规定: 每人只讲且必须讲1门课:每门课必须且只需1人讲. 四人分别讲每门课的费用示于表中: 课 费用 人 A B C D 甲 ...

  10. aws S3存储概念

    S3存储(Simple Storage Service) 存储桶:存储桶是S3中用于存储对象的容器.每个对象都存储在一个存储桶中. 对象:对象是S3中存储的基本实体.对象由对象数据和元数据组成.数据部 ...