题意:给定n<=105的数组h,有m<=105的询问,每个询问为l,r,w求[l,r]区间内连续w个的最小高度最大是多少..

思路:首先把h数组从大到小排序,然后用建立一个可持久化的下标线段树,线段树维护区间最长的连续长度为多少。

那么对于每个询问直接二分高度,然后查询这个高度之前的线段树[l,r]区间是否存在至少w个连续的。。

以前总是套主席树模板,这次自己写感觉也还是蛮好写的。。

据说cdq分治也可搞。。应该是整体二分吧。。明天再想想

code:

 /*
* Author: Yzcstc
* Created Time: 2014/11/10 22:17:29
* File Name: cf276E.cpp
*/
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<stack>
#include<ctime>
#define M0(a) memset(a, 0, sizeof(a))
#define N 101010
#define M 3100000
#define x first
#define y second
#define ls lson[rt]
#define rs rson[rt]
using namespace std;
typedef pair<int, int> pii;
struct node{
int c, lc, rc;
node(int _c = , int _lc = , int _rc = ):c(_c), lc(_lc), rc(_rc){}
};
pair<int, int> p[N];
int T[N], lc[M], rc[M], c[M], lson[M], rson[M], tot;
int n, m; int build(const int l, const int r){
int root = tot++;
c[root] = lc[root] = rc[root] = ;
if (l < r){
int mid = (l + r) >> ;
lson[root] = build(l, mid);
rson[root] = build(mid+, r);
}
return root;
} void push_up(const int& rt, const int& llen, const int &rlen){
lc[rt] = (c[ls] >= llen) ? llen + lc[rs] : lc[ls];
rc[rt] = (c[rs] >= rlen) ? rlen + rc[ls] : rc[rs];
c[rt] = max(c[ls], c[rs]), c[rt] = max(lc[rs] + rc[ls], c[rt]);
} int update(const int rt, const int l, const int r, const int& p){
int root = tot++;
if (p <= l && r <= p){
c[root] = rc[root] = lc[root] = ;
return root;
}
int mid = (l + r) >> ;
lson[root] = ls, rson[root] = rs;
if (p <= mid)
lson[root] = update(ls, l, mid, p);
else
rson[root] = update(rs, mid+, r, p);
push_up(root, mid-l+, r-mid);
return root;
} node tmp, t;
void merge(node &a, const node& b,const int& llen,const int& rlen){
t.c = max(a.c, b.c), t.c = max(t.c, a.rc + b.lc);
t.lc = (a.lc >= llen) ? a.lc + b.lc : a.lc;
t.rc = (b.rc >= rlen) ? b.rc + a.rc : b.rc;
a = t;
} node query(const int& rt,const int& l,const int& r,const int& L,const int& R){
if (L <= l && r <= R) return node(c[rt], lc[rt], rc[rt]);
int mid = (l + r) >> ;
if (R <= mid) return query(ls, l, mid, L, R);
else if (L > mid) return query(rs, mid + , r, L, R);
else{
node res = query(ls, l, mid, L, R);
tmp = query(rs, mid+, r, L, R);
merge(res, tmp, mid - max(L, l) + , min(R,r) - mid);
return res;
}
} void init(){
scanf("%d", &n);
tot = ;
for (int i = ; i <= n; ++i)
scanf("%d", &p[i].x), p[i].y = i;
sort(p + , p + + n, greater<pii>() );
} void solve(){
T[] = build(, n);
for (int i = ; i <= n; ++i)
T[i] = update(T[i-], , n, p[i].y);
int q, ll, rr, w, l, r, mid, ans;
scanf("%d", &q);
while (q--){
scanf("%d%d%d", &ll, &rr, &w);
l = , r = n, ans = ;
while (l <= r){
mid = (l + r) >> ;
if (query(T[mid], , n, ll, rr).c >= w){
ans = max(ans, p[mid].x);
r = mid - ;
} else l = mid + ;
}
printf("%d\n", ans);
} } int main(){
init();
solve();
return ;
}

codeforces 484E的更多相关文章

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

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

  2. Sign on Fence CodeForces - 484E

    http://codeforces.com/problemset/problem/484/E 题意: 给定一个长度为n的数列,有m次询问,询问形如l r k 要你在区间[l,r]内选一个长度为k的区间 ...

  3. AC日记——Sign on Fence Codeforces 484e

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

  4. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

  5. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  6. 【Codeforces 738C】Road to Cinema

    http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...

  7. 【Codeforces 738A】Interview with Oleg

    http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...

  8. CodeForces - 662A Gambling Nim

    http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...

  9. CodeForces - 274B Zero Tree

    http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...

随机推荐

  1. redis 数据类型

    上一篇文章主要写了redis在linux下的安装,这里讲一下redis基本的数据类型,linux的数据类型比较丰富,主要有五种数据类型 .String 字符串类型 常用命令: 除了get.set.in ...

  2. PHP 之 this self parent static 对比

    this 绑定的是当前已经实例化的对象 这样长出现的问题: 如果你在一个父类中使用$this调用当前一个类的方法或者属性,如果这个类被继承,且在相应的子类中有调用的属性或者方法是,则父类中的$this ...

  3. X64操作系统组件Jmail无法正常服务问题

    故障现象: 近日,在VMware虚拟化部署迁移中,之前物理服务器中部署网站ASP组件Jmail服务一切正常,迁移完成后发现Jmail无法正常工作,其余组件能正常工作. 环境:Windows Serve ...

  4. Module 'fileinfo' already loaded in Unknown on line 0

    出现的原因是:需要加载的扩展已经以而二进制文件的形式写入了php中,但是,在php.ini中却再一次动态加载 参考出处

  5. inotify resources exhausted

    inotify resources exhausted tail -f /var/log/kubelet.log tail: inotify resources exhausted tail: ino ...

  6. VS2013开发 windows服务 挂到服务器上执行

    这是百度经验的链接,本人主要参考的他.http://jingyan.baidu.com/article/cd4c2979e9330d756f6e6070.html 1 创建windows服务项目 2 ...

  7. IIS发布WCF服务项目之本地

    最近由于项目需求,要做一个上传文件附件的功能,由于是多用户访问,所以这就用到了WCF服务,程序编写完成就需要发布了, 下面记录下发布到IIS的过程: 1,安装IIS 第一步:检查Windows7中II ...

  8. 手把手写php框架中三大“自动功能”

    在很多php框架中都有自动过滤,自动填充,自动验证等三大自动功能,用来对POST表单传过来的数据进行加工,以便能够更加规范的导入数据库.这一功能在添加商品,添加商品分类中有很大的用处.比如thinkp ...

  9. ListView13添加2

    Columns=//添加列总行的标题 GridLines=true //显示网格线 添加数据------------- listView1.Items.Add("123123123" ...

  10. jQuery操作Table tr td常用的方法

    虽然现在DIV+CSS进行页的布局大行其道,但是很多地方使用table还是有很多优势,用table展示数据是比较方便的,下面汇总了jQuery操作Table tr td常用的方法,熟记这些操作技巧,下 ...