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. print a float number with 3 digits following

    just use the java's printf function. It is like C's printf. System.out.printf("%.3f\n", x) ...

  2. contact form

    use the existing service: http://www.foxyform.com/

  3. jquery checkbox 操作

    1.jquery 获取所有选中和未选中的checkbox 未选中 var unCheckedBoxs = $("input[name='myCheckbox']").not(&qu ...

  4. 怎样让pl sql developer 界面视图复位

    tools->preferences->user interface->appearance->reset docking工具-首选项-用户界面-外观-复位停放

  5. HTML+CSS D07 边框、div

    1.边框(border) 常用表达 border-width px thin 定义细的边框. medium 默认.定义中等的边框. thick 定义粗的边框. length 允许您自定义边框的宽度. ...

  6. Cookie 的设置和获取

    获取:var userName = getCookieValue("userName"); 设置:setCookie("userName",equpid,24, ...

  7. C语言根据函数名调用对应的函数

    通过函数指针定义,调用时加上参数 struct Command { const char *name; const char *desc; // return -1 to force monitor ...

  8. mysql 字段的类型有哪些

    int型包括(tinyint, smallint, mediumint, int, bigint) tinyint是1个字节表达范围就是2的8次方(-128-128) 或者(0-255) 很多人不明白 ...

  9. UIImagePikerController 浅析

    原文链接:http://www.jianshu.com/p/2ac85aca4468 UIImagePickerController是iOS系统提供的和系统的相册和相机交互的一个类,可以用来获取相册的 ...

  10. 2016中国大学生程序设计竞赛 - 网络选拔赛 1001 A water problem (大数取余)

    Problem Descripton Two planets named Haha and Xixi in the universe and they were created with the un ...