题意:给定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. De4Dot+Reflector 支持多种反混淆

    官网: http://www.de4dot.com/ 源码:https://github.com/brianhama/de4dot 使用方法 通过CMD命令方式进入: F:\2\de4dot-v3-1 ...

  2. 制作Nine-Patch图片的流程

    1.找到draw9patch.bat文件,在Android sdk目录下的tools文件夹中. 2.双击打开draw9patch.bat文件,在导航栏点击File->Open 9-patch将图 ...

  3. js自定义对象

    一,概述 在Java语言中,我们可以定义自己的类,并根据这些类创建对象来使用,在Javascript中,我们也可以定义自己的类,例如定义User类.Hashtable类等等. 目前在Javascrip ...

  4. JVM内存模型和启动参数的关系

    今天开始接触JVM的内存模型这一块的内容,以下这张图是从网上找的,先收藏了,虽然现在还看不太懂.以后弄懂了才进行详细的解说.

  5. 现在还需要测试或者QA人员吗?

    Facebook没有专门的测试人员,都是开发自己测:微软裁掉了测试部门,改由开发测:google有少量的测试人员,主要做测试自动化框架开发或者性能.安全等专项测试,测试用例还是开发人员自己设计自己跑( ...

  6. myql数据库在cmd下,中文乱码的问题原因

    使用navicat把数据导入数据库,这些数据都是中文,导入成功,显式也正常,但是在mysql cmd下都是乱码.检查了我的mysql配置,字符编码都是utf8,包括navicat连接时候也设置过是ut ...

  7. 保护眼睛,把常用软件的背景设置成Dark

    每天长时间使用电脑,很多软件的背景都是白色,久看对眼睛不好. 1)Google Chrome,WebDev/看新闻/看邮件/写博客.使用Stylish插件和Global Dark Style,效果相当 ...

  8. easyui datagrid 加载两次请求,触发两次ajax 请求 问题

    datagrid初始化的时候请求两次URL 两种情况 1. <table id="gridview" class="easyui-datagrid"> ...

  9. ASP.NET ashx实现无刷新页面生成验证码

    现在大部分网站登陆时都会要求输入验证码,在网上也看了一些范例,现在总结一下如何实现无刷新页面生成验证码. 效果图: 实现方式: 前台: <div> <span>Identify ...

  10. ctrip

    #-*-coding:utf8-*-from lxml import etreeimport requestsimport re#编码转换import sysreload(sys)sys.setdef ...