题意:给出,n和飞行员高度h,n是区间数。在区间里飞行员高度不变,其它地方每秒高度-1,x坐标+1。问在高度变为0以前,x坐标最多加多少?

用数组gap记录本区间右端到下一个区间左端的距离。用sum记录gap数组的前i项和(前缀和)。其实飞行员能飞过的gap的距离之和必须小于高度h。那么对于i(表示飞行员从哪个气流的左端开始飞)从0到(n-1)。用lower_bound(sum[i](第i个气流之前的gap的和)+h)查到最远的右端,再用线段树查中间的气流长度和,更新结果。

乱码:

//#pragma comment(linker,"/STACK:1024000000,1024000000")
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include <stack>
#include <list>
using namespace std;
const int SZ=,INF=0x7FFFFFFF;
typedef long long lon;
const double EPS=1e-;
lon arr[SZ],sum[SZ]; void pushup(lon rt)
{
sum[rt]=sum[rt*]+sum[rt*+];
} void build(int ll,int rr,int rt)
{
if(ll>rr)return;
if(ll==rr)
{
sum[rt]=arr[ll];
return;
}
int mid=(ll+rr)/;
build(ll,mid,rt*);
build(mid+,rr,rt*+);
pushup(rt);
} lon qry(int ll,int rr,int rt,int ql,int qr)
{
if(ll>=ql&&rr<=qr)
{
return sum[rt];
}
if(rr<ql||ll>qr)return ;
int mid=(ll+rr)/;
lon res=;
if(rr>=ql)res+=qry(ll,mid,rt*,ql,qr);
if(ll<=qr)res+=qry(mid+,rr,rt*+,ql,qr);
return res;
} int main()
{
//std::ios::sync_with_stdio(0);
//freopen("d:\\1.txt","r",stdin);
lon n,h;
cin>>n>>h;
vector<lon> gap,gsum;
for(int i=;i<n;++i)
{
lon x,y,oldy;
cin>>x>>y;
if(i)
{
gap.push_back(x-oldy);
}
arr[i+]=y-x;
oldy=y;
} if(n==)
{
cout<<(h+arr[])<<endl;
return ;
} gsum.push_back(gap[]);
for(int i=;i<gap.size();++i)
{
gsum.push_back(gsum[gsum.size()-]+gap[i]);
} lon res=;
build(,n,); for(int i=;i<n;++i)
{
int dst=(i==?:gsum[i-])+h;
int pos=lower_bound(gsum.begin()+i-,gsum.end(),dst)-(gsum.begin()+i-);
res=max(res,qry(,n,,i,i+pos)+h);
}
cout<<res<<endl;
return ;
}

codeforces 1041d// Glider// Codeforces Round #509(Div. 2)的更多相关文章

  1. Codeforces Round #509 (Div. 2)

    咕咕咕了好多天终于有时间写篇博客了_(:з」∠)_ 打网赛打到自闭的一周,终于靠这场CF找回了一点信心... 1041A - Heist \(ans=max\left \{ a_i \right \} ...

  2. Codeforces Round #509 (Div. 2) F. Ray in the tube(思维)

    题目链接:http://codeforces.com/contest/1041/problem/F 题意:给出一根无限长的管子,在二维坐标上表示为y1 <= y <= y2,其中 y1 上 ...

  3. Codeforces Round #509 (Div. 2) E. Tree Reconstruction(构造)

    题目链接:http://codeforces.com/contest/1041/problem/E 题意:给出n - 1对pair,构造一颗树,使得断开其中一条边,树两边的最大值为 a 和 b . 题 ...

  4. Codeforces Round#509 Div.2翻车记

    A:签到 #include<iostream> #include<cstdio> #include<cmath> #include<cstdlib> # ...

  5. Codeforces Round #509 (Div. 2) A. Heist 贪心

    There was an electronic store heist last night. All keyboards which were in the store yesterday were ...

  6. CF Round #509 (Div. 2)

    前言:第一次打\(CF\),因为经验不足以及英语水平很烂,即便在机房大佬的带领下也是花了好久才读懂题目..\(A\)题直到\(11\)分钟才\(A\),题目一共才做了\(4\)题,太菜了.. A. H ...

  7. CF Round #510 (Div. 2)

    前言:没想到那么快就打了第二场,题目难度比CF Round #509 (Div. 2)这场要难些,不过我依旧菜,这场更是被\(D\)题卡了,最后\(C\)题都来不及敲了..最后才\(A\)了\(3\) ...

  8. Codeforces Round #366 (Div. 2) ABC

    Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...

  9. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

随机推荐

  1. linux常用命令:chkconfig 命令

    chkconfig命令用来安装,查看或修改 services随系统启动的启动选项的设置.是Red Hat公司遵循GPL规则所开发的程序,它可查询操作系统在每一个执行等级中会执行哪些系统服务,其中包括各 ...

  2. Java SE 基础知识(二)

    1. 类由两大部分构成:属性和方法.属性一般用名词来表示,方法一般用动词来表示. 2. 如果一个java源文件中定义了多个类,那么这些类中最多只能有一个类是public的,可以都不是public的. ...

  3. (一)github之基础概念篇

    1.github: 一项为开发者提供git仓库的托管服务, 开发者间共享代码的场所.github上公开的软件源代码全都由git进行管理. 2.git: 开发者将源代码存入名为git仓库的资料库中,而g ...

  4. 重启eclips后启动项目出现监听文件找不到

    重启eclips后启动项目出现监听文件找不到 问题: 重启eclips后启动项目出现Error configuring application listener of class com.thinkg ...

  5. dba和运维专家们说有丰富的大型分布式系统架构设计经验纯属扯淡

    如果,一开始就从事dba和运维的专家们说他们有丰富的大型分布式系统架构设计经验,那纯属扯淡.除非,他们从是从开发专家或者架构师转型而来,那么他们才有资格说自己有丰富的大型分布式系统架构设计经验. 运维 ...

  6. android 实践项目 总结 (修改)

    Android手机定位与地图实现 在一个不熟悉的环境中,获得自己的位置,选择合适的就餐地点,住宿和公交路线成为一项难题.本次的实践项目就是为了解决上述难题的,通过调用百度地图的接口实现定位.查询公交路 ...

  7. Ubuntu18.04安装Openssl-1.1.1

    1.查看版本 Ubuntu的版本是18.04.使用openssl version命令查看openssl版本,可以看到Ubuntu自带了openssl-1.1.0版本,因此安装新版本需要替换旧版本. 2 ...

  8. HDU1540 Tunnel Warfare(线段树区间维护&求最长连续区间)题解

    Tunnel Warfare Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)To ...

  9. 同步TreeView中父结点和子结点的状态[以及Treeview的bug]

    此代码仅仅是二级结点,即父结点下面只有一层子结点,只有两层结构 /// <summary> /// 某个结点的CheckBox被选中 /// </summary> /// &l ...

  10. acm模板生成

    为迎接,接下来的区域赛,要做好准备(虽然不是特别有信心,但是还是要鼓励自己,可以取得收获的,加油) acm_latex模板: https://www.cnblogs.com/palayutm/p/64 ...