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. Codeforces 1106E. Lunar New Year and Red Envelopes(DP)

    E. Lunar New Year and Red Envelopes 题意: 在长度为n的时间轴上,有k个红包,每个红包有领取时间段[s,t],价值w,以及领了个这个红包之后,在时间d到来之前无法再 ...

  2. 0ctf-Wallbreaker Easy复现

    补坑+1. 有预留的后门,并且给了phpinfo,因此可以从phpinfo中先搜集一波信息: 这里禁用了很多命令执行的函数,所以应该要bypass_disablefunction,先读一下flag在哪 ...

  3. http协议格式详解

    参考:https://www.jianshu.com/p/8fe93a14754c 一.URI结构 HTTP使用统一资源标识符(URI)来传输数据和建立连接.URL(统一资源定位符)是一种特殊种类的U ...

  4. ndarray的axis问题

    始终记不住np中axis是对应到哪个,还没系统地去学习下 先暂记两个常用的结果 1.[:,np.newaxis] 与 [np.newaxis, :] 注:这是ndarray才有的分片方法(np重写了[ ...

  5. legend3---12、DB::table('user_questions')和UserQuestion查询的结果的格式不一样

    legend3---12.DB::table('user_questions')和UserQuestion查询的结果的格式不一样 一.总结 一句话总结: 推荐使用模型查找的方式,可以直接数组方式访问: ...

  6. 黑马vue---15、使用v-model实现简易计算器

    黑马vue---15.使用v-model实现简易计算器 一.总结 一句话总结: 用v-model绑定了第一个数,第二个数,操作符,和结果,数据改变他们跟着变,他们变数据也跟着变 select v-mo ...

  7. mp3收藏

    [程序员一个]一人饮酒醉 https://kg2.qq.com/node/play?s=lW1J2-lrkrR3klvD&shareuid=619598862d2a31893d&top ...

  8. [MyBatis]最简MyBatis工程

    下载地址:https://files.cnblogs.com/files/xiandedanteng/fillMillionDatum01_191005.rar --END-- 2019年10月5日1 ...

  9. Android系统服务 —— WMS与AMS

    “可以毫不夸张的说,Android的framework层主要是由WMS.AMS还有View所构成,这三个模块穿插交互在整个framework中,掌握了它们之间的关系和每一个逻辑步骤,你对framewo ...

  10. Android:JNA实践(附Demo)

    一.JNA和JNI的对比   1.JNI的调用流程 Android应用开发中要实现Java和C,C++层交互时,想必首先想到的是JNI,但是JNI的使用过程十分繁琐,需要自己再封装一层JNI接口进行转 ...