codeforces 1041d// Glider// Codeforces Round #509(Div. 2)
题意:给出,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)的更多相关文章
- Codeforces Round #509 (Div. 2)
咕咕咕了好多天终于有时间写篇博客了_(:з」∠)_ 打网赛打到自闭的一周,终于靠这场CF找回了一点信心... 1041A - Heist \(ans=max\left \{ a_i \right \} ...
- Codeforces Round #509 (Div. 2) F. Ray in the tube(思维)
题目链接:http://codeforces.com/contest/1041/problem/F 题意:给出一根无限长的管子,在二维坐标上表示为y1 <= y <= y2,其中 y1 上 ...
- Codeforces Round #509 (Div. 2) E. Tree Reconstruction(构造)
题目链接:http://codeforces.com/contest/1041/problem/E 题意:给出n - 1对pair,构造一颗树,使得断开其中一条边,树两边的最大值为 a 和 b . 题 ...
- Codeforces Round#509 Div.2翻车记
A:签到 #include<iostream> #include<cstdio> #include<cmath> #include<cstdlib> # ...
- Codeforces Round #509 (Div. 2) A. Heist 贪心
There was an electronic store heist last night. All keyboards which were in the store yesterday were ...
- CF Round #509 (Div. 2)
前言:第一次打\(CF\),因为经验不足以及英语水平很烂,即便在机房大佬的带领下也是花了好久才读懂题目..\(A\)题直到\(11\)分钟才\(A\),题目一共才做了\(4\)题,太菜了.. A. H ...
- CF Round #510 (Div. 2)
前言:没想到那么快就打了第二场,题目难度比CF Round #509 (Div. 2)这场要难些,不过我依旧菜,这场更是被\(D\)题卡了,最后\(C\)题都来不及敲了..最后才\(A\)了\(3\) ...
- 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 ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
随机推荐
- 在outlook中发邮件判断邮件发送成功的方法
早上给企业发了求职邮件,但是发送的时候,自己发现附件比较大,因为之前比较少使用这个工具来发邮件,所以发送之后没有提醒成功与否,求职心切,内心变得比较紧张. 所以查了查方法,发现了以下解决方案,现备注下 ...
- IOS中position:fixed吸底时的滑动出现抖动的解决方案
H5方法: //吸顶头部 .header{ width:100%; height:50px; position:fixed; top:0px; } //main滑动区域 .main{ width:10 ...
- quartz-job实现定时任务配置
使用quartz开源调度框架,写服务实现在一些指定场景发送特定短信,创建一个实现org.quartz.Job接口的java类.Job接口包含唯一的方法: public void execute(Job ...
- eclispe 相关设置
1. 关闭js文件校验: 1). windows->preference->Java Script->Validator->Errors/Warnings->Enable ...
- 干货:Java多线程详解(内附源码)
线程是程序执行的最小单元,多线程是指程序同一时间可以有多个执行单元运行(这个与你的CPU核心有关). 在java中开启一个新线程非常简单,创建一个Thread对象,然后调用它的start方法,一个 ...
- P3313 [SDOI2014]旅行
P3313 [SDOI2014]旅行 树链剖分+动态线段树(并不是lct) 显然的,我们对于每一个宗教都要维护一个线段树. (那么空间不是爆炸了吗) 在这里引入:动态开点线段树 就是需要的点开起来,不 ...
- 06: linux下python开发环境梳理
1.1 修改~/.bashrc文件 改编终端颜色 alias rm='rm -i' alias cp='cp -i' alias mv='mv -i' # User specific aliases ...
- 利用脚本kill掉进程, 语法:运行脚本+进程名
下面附上脚本, 权限需要附X执行 #!/bin/sh #pid kill thread for chenglee #if fileformat=dos, update fileformat=unix ...
- 20145332 《网络攻防》 逆向与Bof实验
20145332 <网络攻防>逆向与Bof实验 实践目标 本次实践的对象是一个名为pwn1的linux可执行文件. 该程序正常执行流程是:main调用foo函数,foo函数会简单回显任何用 ...
- Codeforces Round#413 Problem A - C
Problem#A Carrot Cakes vjudge链接[here] (偷个懒,cf链接就不给了) 题目大意是说,烤面包,给出一段时间内可以考的面包数,建第二个炉子的时间,需要达到的面包数,问建 ...