题意:给出,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. 实现kylin定时跑当天的任务

    说明: 每天自动构建cube,动态在superset里面查看每天曲线变化图 #! /bin/bash ##cubeName cube的名称 ##endTime 执行build cube的结束时间 (命 ...

  2. python webdriver api-操作日期元素的方法

    操作日期元素 第一种方式直接向输入框输入日期 dateInputBox = self.driver.find_element_by_id("datepicker") dateInp ...

  3. firefox历史版本下载链接

    http://ftp.mozilla.org/pub/firefox/releases firefox版本42以上的用不了firebug,需要装版本42以下的,否则用不了

  4. DeepMind已将AlphaGo引入多领域 Al泡沫严重

    DeepMind已将AlphaGo引入多领域 Al泡沫严重 在稳操胜券的前提下,谷歌旗下的AlphaGo还是向柯洁下了战书.4月10日,由中国围棋协会.浙江省体育局.谷歌三方联合宣布,将于5月23日至 ...

  5. Tomcat8.5 升级tomcat版本导致出现异常,Base64不存在

    Tomcat8.5 升级tomcat版本导致出现异常,Base64不存在 原因分析: 由于tomcat由7升级到8.5导致Base64的引用路径错误,默认引用为8.5中的jar, 解决方案: 修改引用 ...

  6. django 加载静态文件(图片,js,css)

    昨天写过一个项目通过django上传展示图片,但是今天写项目的时候发现出现了问题,静态文件加载不出来了,尴尬的一笔~ 记录一下静态文件的使用方法,基础~ ----------------------- ...

  7. 20162311 编写Android程序测试查找排序算法

    20162311 编写Android程序测试查找排序算法 一.设置图形界面 因为是测试查找和排序算法,所以先要有一个目标数组.为了得到一个目标数组,我设置一个EditText和一个Button来添加数 ...

  8. Python3基础 函数 局部与全局变量同名,各管各的

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

  9. pip 更换国内镜像与记录

    更换pip源到国内镜像 阿里云 http://mirrors.aliyun.com/pypi/simple/   中国科技大学 https://pypi.mirrors.ustc.edu.cn/sim ...

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

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