Bizon the Champion has recently finished painting his wood fence. The fence consists of a sequence of n panels of 1 meter width and of arbitrary height. The i-th panel's height is hi meters. The adjacent planks follow without a gap between them.

After Bizon painted the fence he decided to put a "for sale" sign on it. The sign will be drawn on a rectangular piece of paper and placed on the fence so that the sides of the sign are parallel to the fence panels and are also aligned with the edges of some panels. Bizon the Champion introduced the following constraints for the sign position:

  1. The width of the sign should be exactly w meters.
  2. The sign must fit into the segment of the fence from the l-th to the r-th panels, inclusive (also, it can't exceed the fence's bound in vertical direction).

The sign will be really pretty, So Bizon the Champion wants the sign's height to be as large as possible.

You are given the description of the fence and several queries for placing sign. For each query print the maximum possible height of the sign that can be placed on the corresponding segment of the fence with the given fixed width of the sign.

  纪念人生第一道Div 1的E题,终于搞定了。

  题目就是N个值的M次询问,然后对于一个询问来说就是二分答案。对于M次询问的话,想到了整体二分。然后数据结构的话就是区间合并的线段树,比较经典的问题。

  代码如下:

// ━━━━━━神兽出没━━━━━━
// ┏┓ ┏┓
// ┏┛┻━━━━━━━┛┻┓
// ┃ ┃
// ┃ ━ ┃
// ████━████ ┃
// ┃ ┃
// ┃ ┻ ┃
// ┃ ┃
// ┗━┓ ┏━┛
// ┃ ┃
// ┃ ┃
// ┃ ┗━━━┓
// ┃ ┣┓
// ┃ ┏┛
// ┗┓┓┏━━━━━┳┓┏┛
// ┃┫┫ ┃┫┫
// ┗┻┛ ┗┻┛
//
// ━━━━━━感觉萌萌哒━━━━━━ // Author : WhyWhy
// Created Time : 2016年01月22日 星期五 17时06分36秒
// File Name : L_1.cpp #include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h> using namespace std; const int MaxN=<<; struct OPE { int l,r,w,id; } ope[MaxN],to1[MaxN],to2[MaxN]; int N,M;
int ans[MaxN]; /////////////////////////////// #define lc (po<<1)
#define rc ((po<<1)|1)
#define lson L,M,lc
#define rson M+1,R,rc struct ANS {
int num,lnum,rnum;
ANS(int a=,int b=,int c=):num(a),lnum(b),rnum(c) {}
}; ANS BIT[MaxN<<]; ANS merge(int len1,int len2,ANS a1,ANS a2) {
ANS ret;
ret.num=max(max(a1.rnum+a2.lnum,a1.num),a2.num);
ret.lnum=(len1==a1.num) ? len1+a2.lnum : a1.lnum;
ret.rnum=(len2==a2.num) ? len2+a1.rnum : a2.rnum;
return ret;
} inline void pushUP(int len1,int len2,int po) {
BIT[po]=merge(len1,len2,BIT[lc],BIT[rc]);
} void update(int up,int ut,int L,int R,int po) {
if(L==R) {
BIT[po].num=BIT[po].lnum=BIT[po].rnum=ut;
return;
} int M=(L+R)>>;
if(up<=M) update(up,ut,lson);
else update(up,ut,rson); pushUP(M-L+,R-M,po);
} ANS query(int ql,int qr,int L,int R,int po) {
if(ql<=L && qr>=R) return BIT[po]; int M=(L+R)>>;
if(ql>M) return query(ql,qr,rson);
if(qr<=M) return query(ql,qr,lson); return merge(M-ql+,qr-M,query(ql,M,lson),query(M+,qr,rson)); // !!!
} /////////////////////////////// int tmp[MaxN]; void getans(int ql,int qr,int L,int R) {
if(ql>qr) return;
if(L==R) {
for(int i=ql;i<=qr;++i) ans[ope[i].id]=L;
return;
} int M=(L+R+)>>;
for(int i=ql;i<=qr;++i)
if(!ope[i].id && ope[i].w>=M)
update(ope[i].l,,,N,),tmp[i]=;
else if(ope[i].id && ope[i].w<=query(ope[i].l,ope[i].r,,N,).num)
tmp[i]=;
else tmp[i]=; int cou1=,cou2=;
for(int i=ql;i<=qr;++i)
if(tmp[i]) {
to2[cou2++]=ope[i];
if(tmp[i]==) update(ope[i].l,,,N,);
}
else to1[cou1++]=ope[i]; int t=ql;
for(int i=;i<cou1;++i) ope[t++]=to1[i];
for(int i=;i<cou2;++i) ope[t++]=to2[i]; getans(ql+cou1,qr,M,R); // !!! 大的那些要被用到,在小的里面。 for(int i=ql+cou1;i<=qr;++i)
if(!ope[i].id)
update(ope[i].l,,,N,); getans(ql,ql+cou1-,L,M-);
} /////////////////////////////// int main() {
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout); int t,cou=;
scanf("%d",&N);
for(int i=;i<=N;++i) {
scanf("%d",&t);
ope[++cou].w=t;
ope[cou].l=i;
ope[cou].id=;
}
scanf("%d",&M);
for(int i=;i<=M;++i) {
ope[++cou].id=i;
scanf("%d %d %d",&ope[cou].l,&ope[cou].r,&ope[cou].w);
}
getans(,cou,,);
for(int i=;i<=M;++i) printf("%d\n",ans[i]); return ;
}

最新文章

  1. su与su-
  2. JavaScript-计算器
  3. BROOTKIT Pinciple、Code Analysis(undone)
  4. Bootstrap《第一篇》,关于container、jumbotron、row、col、text-center等的学习
  5. thinkphp中文验证码不能显示的问题
  6. python 的一些小技巧
  7. Alert()与Redirect()同时使用失效的问题
  8. Cache 和 Buffer 都是缓存,主要区别是什么?
  9. tomcat加入系统服务+开机自启
  10. 规约模式(Specification Pattern)
  11. DAY1 VS2017&amp;CUDA10.01环境搭建
  12. 深入解读阿里云数据库POLARDB核心功能物理复制技术
  13. 第十六节、特征描述符BRIEF(附源码)
  14. html基本进阶知识【转】
  15. 2018牛客网暑假ACM多校训练赛(第四场)A Ternary String 数论
  16. java可供判断某字符串是什么编码的一行代码
  17. linux(centos)测试带宽
  18. SpringBoot的spring-boot-starter有哪些(官方)
  19. xmind指定32位jdk解决在64位系统上不能启动的问题
  20. docker 相关文章

热门文章

  1. Ansible9:条件语句【转】
  2. 安卓无法生成R文件原因
  3. js.map error
  4. iOS项目架构 小谈
  5. Android中Canvas绘图基础详解(附源码下载) (转)
  6. Android :android.os.Process.myTid()与 Thread.currentThread().getId();
  7. img图片inline-block总结
  8. JSch - Java实现的SFTP
  9. opencv ,亮度调整【【OpenCV入门教程之六】 创建Trackbar &amp; 图像对比度、亮度值调整
  10. [code]字母重排