题意:给出,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. python 冒泡排序的总结

    冒泡排序: 思路: 3 5 1 6 2 第一次:找到这些书中最大的一个,并把它放到最后 3.5找到大的数放到第二个位置1.5 5.1找到大的数放到第三个位置1.5.1 5.6找到大的数放到第四个位置 ...

  2. java笔试题三(javaWeb)

    1.讲一下Servlet的执行过程,doGet和doPost的区别. 执行过程: 比如注解配置版本,先继承httpServlet,一旦发送get请求 调用,再执行post方法. doGet和doPos ...

  3. Python Web学习笔记之并发和并行的区别和实现

    你吃饭吃到一半,电话来了,你一直到吃完了以后才去接,这就说明你不支持并发也不支持并行.你吃饭吃到一半,电话来了,你停了下来接了电话,接完后继续吃饭,这说明你支持并发.你吃饭吃到一半,电话来了,你一边打 ...

  4. finedb(内置的HSQL数据库)迁移数据到MySQL

    finedb(内置的HSQL数据库)迁移数据到MySQL 1. 前言 在FineBI中,决策平台的数据(用户.角色.组织机构.权限等信息)是存储在finedb数据库中的,默认情况下finedb是一个内 ...

  5. java反射field和method的顺序问题

    最近在有思考到序列化性能优化的问题,关于java反射field和method的顺序问题,这里有详细的讨论http://stackoverflow.com/questions/5001172/java- ...

  6. 高通平台读写nv总结【转】

    本文转载自:https://blog.csdn.net/suofeng12345/article/details/52713993 一,引言      1. 什么是NV       高通平台的NV,保 ...

  7. jz2440-linux3.4.2-kernel移植【学习笔记】【原创】

    平台:jz2440 作者:庄泽彬(欢迎转载,请注明作者) 说明:韦东山二期视频学习笔记 交叉编译工具:arm-linux-gcc (GCC)4.3.2 linux:linu3.4.2 PC环境:ubu ...

  8. 详解C中的volatile关键字【转】

    本文转载自:http://www.cnblogs.com/yc_sunniwell/archive/2010/06/24/1764231.html volatile提醒编译器它后面所定义的变量随时都有 ...

  9. 如何创建自己的python包

    写过python的人都知道python最方便也最牛的地方就是它有无数的第三方lib可以直接拿来使用,可以让编写代码变的更容易. 长用的安装第三方lib的方法有easy_install和pip,这两个的 ...

  10. ubuntu下交叉编译imagemagick

    环境:ubuntu16.04 交叉编译器版本号:4.8.3 在编译之前要编译以下其依赖的软件或库:freetype,libpng,libxml2,libtiff,libjpeg,zlib,graphv ...