题意:给出,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. 【转】eclipse反编译插件

    原文地址:http://bbs.csdn.net/topics/390263414 离线安装包下载地址一:http://feeling.sourceforge.net/downloads/org.sf ...

  2. 新项目新工作空间新仓库新setting文件

     maven项目涉及到仓库,本地jar包存放在本地仓库中,新项目新工作空间新仓库新setting文件,可以避免很多问题,不同项目工程的版本可能不一样,所涉及的jar包版本可能也不一样,不分开会有一些冲 ...

  3. jQuery 遍历 - eq() 方法 查找当前元素

    jQuery 遍历 - eq() 方法 if(data[i].status !='已送达'){ $('.w-beget').eq(i).attr('disabled','disabled'); }

  4. Linux服务器配置---安装centos

    安装centos 1.插入光盘,启动,可以选择第一项进行安装 2.根据实际需求,一般会选择skip 3.选择语言“简体中文” 4.选择第一项 5.设置主机名字,使用默认 6.选择时区 7.设置超级用户 ...

  5. pyDay1

    1.import python中的import语句是用来导入模块的. 在python的模块库中有大量的模块可供使用,要想使用这些文件需要用import语句把指定模块导入到当前程序中, 使用方法例如: ...

  6. PHP-ThinkPHP5砍价活动相关设计

    近期我们公司项目里陆陆续续有很多为了招引新用户的活动推出,砍价的活动由我来负责,我们的项目是在微信浏览器里供用户浏览访问. 大概描述:进入砍价活动列表页选择有意向的商品,用户点击商品图片可以看到WEB ...

  7. scrapy运行方式

    1,在cmd 命令行下执行 scrapy crawl  demo (爬虫主逻辑的 name= 'demo '的名字) 2, 也可以在spider目录下添加一个py文件,加入以下代码 from scra ...

  8. log4j.properties配置详解与实例

    log4j.properties配置详解与实例 第一步:加入log4j-1.x.x.jar到lib下. 第二步:在工程的src下下建立log4j.properties.内容如下: #OFF,syste ...

  9. 20145331魏澍琛 《网络对抗技术》 PC平台逆向破解

    20145331魏澍琛 <网络对抗技术> PC平台逆向破解 学习任务 1.shellcode注入:shellcode实际是一段代码,但却作为数据发送给受攻击服务器,将代码存储到对方的堆栈中 ...

  10. Oracle RAC(Real Application Clusters)とは

    ここからはOracle RAC(Real Application Clusters)の基本的な概念について述べていきたいと思います. 「RAC」の読み方は普通に「ラック」です. その前に.通常のデータ ...