codeforces 484E
题意:给定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的更多相关文章
- Codeforces 484E Sign on Fence(是持久的段树+二分法)
题目链接:Codeforces 484E Sign on Fence 题目大意:给定给一个序列,每一个位置有一个值,表示高度,如今有若干查询,每次查询l,r,w,表示在区间l,r中, 连续最长长度大于 ...
- Sign on Fence CodeForces - 484E
http://codeforces.com/problemset/problem/484/E 题意: 给定一个长度为n的数列,有m次询问,询问形如l r k 要你在区间[l,r]内选一个长度为k的区间 ...
- 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 ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
- 【Codeforces 738A】Interview with Oleg
http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...
- CodeForces - 662A Gambling Nim
http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...
- CodeForces - 274B Zero Tree
http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...
随机推荐
- 逐个访问URL的每个查询字符串参数
下面介绍一个函数,用于处理location.search的结果,以解析查询字符串,然后返回包含所有参数的一个对象. 比如 www.baidu.com?q=javascript&num=10 ...
- python学习之——eclipse+pydev 环境搭建
最终选用 eclipse+pydev,网上相关资料也是极多的~~~ 1.安装python: 2.安装eclipse: 3.eclipse中安装pydev,eclipse中help—>eclipl ...
- 网络-->监控-->OID-->BGP
说明:暂时发现只适合cisco设备,h3c的交换机只支持部分OID(支持版本.AS号.ROUTER-ID)
- csrf跨站请求伪造
如何杜绝跨站请求伪造? 1.要让服务器知道本次请求是不是冒用了用户的身份→ 2.服务器发给用户一个凭证,用户请求时需携带此凭证→ 3.此凭证只能用户看到而且冒用者看不到→ 4.这就用到了浏览器的安全机 ...
- HTML可编辑的select
HTML可编辑的select实现原理还是用select和input伪装成的! <!DOCTYPE html PUBLIC "-//W3C//Dth XHTML 1.0 Transiti ...
- Java 验证码、二维码
Java 验证码.二维码 资源 需要: jelly-core-1.7.0.GA.jar网站: http://lychie.github.io/products.html将下载下来的 jelly ...
- 用Action的属性接受参数
版本, @Override是Java5的元数据,自动加上去的一个标志,告诉你说下面这个方法是从父类/接口 继承过来的,需要你重写一次,这样就可以方便你阅读,也不怕会忘记@Override是伪代码,表示 ...
- ASP.NET中的XML和JSON
一.DOM简介 1.XML 定义:XML是一种跨语言.跨平台的数据储存格式 2.什么是DOM DOM(document object model)文档对象模型:是一种允许程序或脚本动态的访问更新文档内 ...
- postgreSQL 统计语句
pg_stat_statements 是 postgresql 的一个扩展,用来统计查询语句,类似于 mysql 的 慢查询. 安装二进制文件 有些发行版可能没有附带这个扩展,则需要用户自己安装, 本 ...
- Android(Xamarin)之旅(五)
2016年1月23日,北京迎来了很痛苦的一天,冻死宝宝了,一天都没有出我自己的小黑屋,在这屋子里自娱自乐.不知道你们呢 对于android的四大基本组件(Activity.Service.Broadc ...