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 ;
}

(困难) CF 484E Sign on Fence,整体二分+线段树的更多相关文章

  1. 【BZOJ-3110】K大数查询 整体二分 + 线段树

    3110: [Zjoi2013]K大数查询 Time Limit: 20 Sec  Memory Limit: 512 MBSubmit: 6265  Solved: 2060[Submit][Sta ...

  2. CF 484E - Sign on Fence

    E. Sign on Fence time limit per test 4 seconds memory limit per test 256 megabytes input standard in ...

  3. 【LUOGU???】WD与地图 整体二分 线段树合并

    题目大意 有一个简单有向图.每个点有点权. 有三种操作: 修改点权 删除一条边 询问和某个点在同一个强连通分量中的点的前 \(k\) 大点权和. \(n\leq 100000,m,q\leq 2000 ...

  4. P5163-WD与地图【tarjan,整体二分,线段树合并】

    正题 题目链接:https://www.luogu.com.cn/problem/P5163 题目大意 给出\(n\)个点\(m\)条有向边,点有权值,要求支持操作 删除一条边 修改一个点的权值 求一 ...

  5. BZOJ 3110 [ZJOI2013]K大数查询 (整体二分+线段树)

    和dynamic rankings这道题的思想一样 只不过是把树状数组换成线段树区间修改,求第$K$大的而不是第$K$小的 这道题还有负数,需要离散 #include <vector> # ...

  6. BZOJ3110 K大数查询 【线段树 + 整体二分 或 树套树(非正解)】

    Description 有N个位置,M个操作.操作有两种,每次操作如果是1 a b c的形式表示在第a个位置到第b个位置,每个位置加入一个数c 如果是2 a b c形式,表示询问从第a个位置到第b个位 ...

  7. Codeforces 484E Sign on Fence(是持久的段树+二分法)

    题目链接:Codeforces 484E Sign on Fence 题目大意:给定给一个序列,每一个位置有一个值,表示高度,如今有若干查询,每次查询l,r,w,表示在区间l,r中, 连续最长长度大于 ...

  8. 【BZOJ4009】[HNOI2015]接水果 DFS序+整体二分+扫描线+树状数组

    [BZOJ4009][HNOI2015]接水果 Description 风见幽香非常喜欢玩一个叫做 osu!的游戏,其中她最喜欢玩的模式就是接水果.由于她已经DT FC 了The big black, ...

  9. BZOJ 4009: [HNOI2015]接水果 (整体二分+扫描线 树状数组)

    整体二分+扫描线 树状数组 具体做法看这里a CODE #include <cctype> #include <cstdio> #include <cstring> ...

随机推荐

  1. SharePoint 2010 应用url参数过滤列表视图数据(应用get办法过滤列表数据)

    名人名言:读活书,活读书,读书活.——郭沫若 题目其实不知道如何称呼才干合适大师的搜刮习惯.以便有类似题目经由过程百度或google可以搜刮到,其实就是在url后面添加参数过滤显示我们想要的成果,有人 ...

  2. iOS申请真机调试证书 -- 图文详解

    请参考这篇文章 : http://ios.9tech.cn/news/2013/1011/33117.html 这篇文章完全就是对的,主要是最后一步 “配置Xcode" 图没有配全,也配得不 ...

  3. iOS9以后 GDataXMLNode修改方式

    iOS9以后GDataXMLNode修改方式

  4. Toolbar Painter 工具条制作

    工具条制作工具(ToolBarPainter2013.exe),专为程序猿设计,界面开发必备.当用VC编程制作工具条时,需要为工具栏上每一个button添加图标,是一件极其繁琐的事情,该工具可利用已有 ...

  5. drupal错误: Maximum execution time of 240 seconds exceeded

    drupal7.5安装完成,导入汉化包时,出现错误: Fatal error: Maximum execution time of 240 seconds exceeded in D:\phpweb\ ...

  6. Redis 笔记

    Redis是一个key-value存储系统.和Memcached类似,但是解决了断电后数据完全丢失的情况,而且她支持更多无化的value类型,除了和string外,还支持lists(链表).sets( ...

  7. 【转】ThinkPHP 页面跳转

    ThinkPHP 提供了success 与error 方法用于带提示信息的页面跳转,如添加数据后显示提示信息并跳转等.success 方法用于操作成功后的提示,error 用于操作失败后的提示,二者使 ...

  8. JSTL标签库---SUN公司开发的标签库

    JSTL里的标签包含五大类标签: 核心标签库 国际化标签 JSTL函数(EL函数) 数据库标签// 操作数据库的,用不到了 XML标签//操作XML的,用不到了 都在jstl.jar,standar. ...

  9. 小蚂蚁搬家<贪心>

    题意: 由于预知未来可能会下雨,所以小蚂蚁决定搬家.它需要将它的所有物品都搬到新家,新家的体积为V,小蚂蚁有N件物品需要搬,每件物品的体积为Ai,但他发现:每件物品需要新家剩余体积大于等于Bi才能使它 ...

  10. KVC 实战浅析

    KVC 就是 key value coding,废话! 今天我们研究的是如何使用它! key value coding : 间接通过字符串类型的key取出对应的属性值 KVC的价值 1.可以访问私有成 ...