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. Transformer的PyTorch实现--转载

    转载自 https://blog.csdn.net/stupid_3/article/details/83184691

  2. js面向对象学习笔记

    1.函数的定义方式 第一种定义方式 function fn1() { alert("fn1"); } alert(fn) 函数就是一个特殊的对象,是一个Function类的实例,其 ...

  3. 5.13T1Send 题(send)

    Send 题(send) [题目描述] 某个国家有

  4. When you want to succeed as bad as you wanna breathe, then you’ll be successful.

    上周末登了次山,回来就各种矫情犯懒.今天周四一周又要完蛋,我发现自己真的是对时间流逝无可奈何.然后中午看了把小码哥网站还有MJ博客什么的,各种首期班大爆照,心中羞愧无比.年纪大也不能放弃自己啊,要不人 ...

  5. python 装饰器,传递类以及参数

    #!/usr/bin/env python # coding=utf- import time #import redis class RedisLock(object): def __init__( ...

  6. Jquery 2.0+版本不支持IE8,如何解决?

    用了JQuery2.0+以后,在IE8下会报错,下面是我的方法. 先看代码: <!--[if !IE]> -->        <script src="/Scrip ...

  7. SRS之SrsHls::on_audio详解

    1. SrsHls::on_audio 将音频数据封装到 ts 文件中. /* * mux the audio packet to ts. * @param shared_audio, directl ...

  8. bootstrp的datetimepicker插件获取选定日期

    碰到一个日期选择,并将日期存储到数据库的需求,需要利用bootstrp的datetimepicker插件获取选定日期,并将其转换为指定字符窜,简单记录下实现的过程. 1. datetimepicker ...

  9. Elasticsearch 空值过滤

    参考:https://blog.csdn.net/zhang862520682/article/details/80333196 参考:https://www.jianshu.com/p/7a5d70 ...

  10. React Native的ListView的布局使用

    1> ListView组件用于显示一个垂直的滚动列表,其中的元素之间结构近似而仅数据不同. ListView更适于长列表数据,且元素个数可以增删.和ScrollView不同的是,ListView ...