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);
#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)的更多相关文章
- 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 ...
- A.Who is better?(The Preliminary Contest for ICPC Asia Xuzhou 2019)
https://nanti.jisuanke.com/t/41383 解: 斐波那契博弈+中国剩余定理. #include <bits/stdc++.h> using namespace ...
- 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 ...
- H.Holy Grail ( floyd )(The Preliminary Contest for ICPC Asia Nanjing 2019)
题意: 给出一个有向图,再给出6条原来不存在的路径,让你在这6条路径上添加一个最小的数,使图不存在负环. 思路: 直接6遍 floyd 输出就行了. #include <bits/stdc++. ...
- 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 ...
- 计蒜客 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
A:Who is better? 题目链接:https://nanti.jisuanke.com/t/41383 题意: 类似于有N个石子,先手第一次不能拿完,每次后手只能拿 1 到 前一次拿的数量* ...
- 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 ...
- The Preliminary Contest for ICPC Asia Xuzhou 2019 E XKC's basketball team(排序+二分)
这题其实就是瞎搞,稍微想一想改一改就能过. 排序按值的大小排序,之后从后向前更新node节点的loc值,如果后一个节点的loc大于(不会等于)前一个节点的loc,就把前一个节点的loc值设置为后面的l ...
随机推荐
- Makefile(三)
在平时使用中,可以使用以下的makefile来编译单独的代码 src = $(wildcard *.c) obj = $(patsubst %.c, %.o, $(src)) CC = gcc CFL ...
- 调用七牛云存储文件,返回url
文档地址:https://developer.qiniu.com/kodo/sdk/1283/javascript#2 npm引入 npm install qiniu-js 例子: var obser ...
- linux上安装nginx详细步骤
一.安装依赖包 yum install gcc gcc-c++ pcre-devel patch libffi-devel python-devel zlib-devel bzip2-devel op ...
- 7.20套娃(tao)
套娃(tao) input7 39 53 710 65 102 610 104 110 53 53 9output012 sol: 把查询想象成(x1,y1)向(x2,y2)有边当且仅当(x1< ...
- [转载]作为理工科学生,我们为什么要练就好的文笔?我们需要发blog来记录学习历程?
文/JoeyChen 工程师该怎样才能突破自己的能力瓶颈?写 blog! 工程师该怎样精进自己在职涯上所需要的能力?写 blog! 工程师该怎样才能保持学习与成长的动能?写 blog! 工程师该怎样才 ...
- 2017 ZSTU寒假排位赛 #7
题目链接:https://vjudge.net/contest/149498#overview. A题,水题,直接按照题意模拟一下即可. B题,我用的是线段树.大力用的差分标记(上次听zy说过,下次再 ...
- moveUp()
这个函数内容有点多,想讲一下大概思路: 向上移有两种情况1.前面为空白 这种情况有两个步骤 (1)将人当前的位置设置为空白(0), (2)再讲人前面的位置设置为人(2)2.前面为箱子 当前面为箱子时有 ...
- FFmpeg之avformat_alloc_context()
1. avformat_alloc_context /** * Allocate an AVFormatContext. * avformat_free_context() can be used t ...
- tensorflow中一个矩阵和一个向量相加
import tensorflow as tf x=tf.constant([[1,2],[3,4]]) y=tf.constant([[1],[1]])#列向量 z=tf.constant([1,1 ...
- VC 实现程序只运行一个实例,并激活已运行的程序
转载:http://blog.sina.com.cn/s/blog_4b44e1c00100bh69.html 进程的互斥运行:CreateMutex函数实现只运行一个程序实例 正常情况下,一个进程的 ...