(困难) CF 484E Sign on Fence,整体二分+线段树
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:
- The width of the sign should be exactly w meters.
- 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,整体二分+线段树的更多相关文章
- 【BZOJ-3110】K大数查询 整体二分 + 线段树
3110: [Zjoi2013]K大数查询 Time Limit: 20 Sec Memory Limit: 512 MBSubmit: 6265 Solved: 2060[Submit][Sta ...
- CF 484E - Sign on Fence
E. Sign on Fence time limit per test 4 seconds memory limit per test 256 megabytes input standard in ...
- 【LUOGU???】WD与地图 整体二分 线段树合并
题目大意 有一个简单有向图.每个点有点权. 有三种操作: 修改点权 删除一条边 询问和某个点在同一个强连通分量中的点的前 \(k\) 大点权和. \(n\leq 100000,m,q\leq 2000 ...
- P5163-WD与地图【tarjan,整体二分,线段树合并】
正题 题目链接:https://www.luogu.com.cn/problem/P5163 题目大意 给出\(n\)个点\(m\)条有向边,点有权值,要求支持操作 删除一条边 修改一个点的权值 求一 ...
- BZOJ 3110 [ZJOI2013]K大数查询 (整体二分+线段树)
和dynamic rankings这道题的思想一样 只不过是把树状数组换成线段树区间修改,求第$K$大的而不是第$K$小的 这道题还有负数,需要离散 #include <vector> # ...
- BZOJ3110 K大数查询 【线段树 + 整体二分 或 树套树(非正解)】
Description 有N个位置,M个操作.操作有两种,每次操作如果是1 a b c的形式表示在第a个位置到第b个位置,每个位置加入一个数c 如果是2 a b c形式,表示询问从第a个位置到第b个位 ...
- Codeforces 484E Sign on Fence(是持久的段树+二分法)
题目链接:Codeforces 484E Sign on Fence 题目大意:给定给一个序列,每一个位置有一个值,表示高度,如今有若干查询,每次查询l,r,w,表示在区间l,r中, 连续最长长度大于 ...
- 【BZOJ4009】[HNOI2015]接水果 DFS序+整体二分+扫描线+树状数组
[BZOJ4009][HNOI2015]接水果 Description 风见幽香非常喜欢玩一个叫做 osu!的游戏,其中她最喜欢玩的模式就是接水果.由于她已经DT FC 了The big black, ...
- BZOJ 4009: [HNOI2015]接水果 (整体二分+扫描线 树状数组)
整体二分+扫描线 树状数组 具体做法看这里a CODE #include <cctype> #include <cstdio> #include <cstring> ...
随机推荐
- MJExtension的使用
1. Plist → 模型数组 控制器中引用#import "MJExtension.h" 模型数组 = [模型类名 objectArrayWithFilename:@" ...
- React和动态网站接口的经济学
来自: React and the economics of dynamic web interfaces 自从2000开始我就一直在做web开发,曾见过很多以各种库和框架的起起落落,这些库和框架作为 ...
- Linux查看CPU和内存使用情况 【转】
Linux查看CPU和内存使用情况 在系统维护的过程中,随时可能有需要查看 CPU 使用率,并根据相应信息分析系统状况的需要.在 CentOS 中,可以通过 top 命令来查看 CPU 使用状况.运行 ...
- File类与FileInfo类区别
ile类是静态的,FileInfo不是静态的也没有静态的方法,仅可用于实例化的对象.FileInfo方法基本类似于File.关于二者,作何选择. ● 如果仅进行单一方法调用,则可以使用静态File类上 ...
- pro文件常用内容
qmake生成的pro文件中常用变量 SUBDIRS 指定子目录 TARGET 指定生成的应用程序名(默认为项目名) DEPENDPATH 指定程序编译时依赖的相关路径 INCLUDEPATH 指定头 ...
- MySQL的数据类型【总结】
1.时间类型 MySQL的DateTime,TimeStamp,Date和Time数据类型. DATETIME类型用在你需要同时包含日期和时间信息的值时.MySQL检索并且以'YYYY-MM-DD H ...
- css:cdata
javascript <![CDATA[的web标准使用方法 根据W3C XHTML 1.0的规定:在XHTML中,因为<和&这两个符号有特殊意义(小于号用于标签的开始标记), ...
- C#中使用正则表达式提取超链接地址的集中方法
一般在做爬虫或者CMS的时候经常需要提取 href链接或者是src地址.此时可以使用正则表达式轻松完成. Regex reg = new Regex(@"(?is)<a[^>]* ...
- Java BigDecimal Class
Using BigDecimal to perform precise calculations with floats. BigDecimal is a class type. So declare ...
- 删除 win8.1中的网络1,网络2,宽带连接1,宽带连接2等网络记录
新建txt文本,保存如下内容为reg文档: Windows Registry Editor Version 5.00 [-HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\W ...