codeforces 484E

时间:2022-12-17 19:49:32

题意:给定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&lpar;是持久的段树&plus;二分法&rpar;

    题目链接: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爬虫学习&lpar;5&rpar; —— 扒一下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. 整体二分QAQ

    POJ 2104 K-th Number 时空隧道 题意: 给出一个序列,每次查询区间第k小 分析: 整体二分入门题? 代码: #include<algorithm> #include&l ...

  2. oracle,mysql对敏感,关键字等处理

    oracle用""  比如,处理字段中间有空格,

  3. Unity4&period;3&period;3激活

    Unity4.X Win版本的破解方法: <ignore_js_op> 1.安装unity4.X,一路按提示下一步,要断网,直到激活运行软件后再联网2.将Unity 4.x Pro Pat ...

  4. ssma for oracle

    SQL Server Migration Assistant (SSMA) for Oracle lets you quickly convert Oracle database schemas to ...

  5. JS document 获取 html对象的问题

    在了解document.getElementById()方法的时候,没有留意到被获取的对象的声明时的位置, 一个很基础很细节的问题. 比如说 这个js的引入位置: -----------------a ...

  6. import os&comma; glob&comma; fnmatch--Python os&sol;glob&sol;fnmatch主要函数总结

    auther: Lart date: 2019-01-17 update: 2019-01-18 09:55:36 --- import os, glob, fnmatch 针对某些操作, 官方推荐这 ...

  7. Proxy代理模式

    https://www.cnblogs.com/vincentzh/p/5988145.html https://www.cnblogs.com/wrbxdj/p/5267370.html(不错)

  8. c&plus;&plus; 条件变量

    .条件变量创建 静态创建:pthread_cond_t cond=PTHREAD_COND_INITIALIZER; 动态创建:pthread_cond _t cond; pthread_cond_i ...

  9. &period;NetCore中EFCore的使用整理(二)-关联表查询

    EF常用处理关联加载的方式有3中:延迟加载(Lazy Loading).贪婪加载 (Eager Loading)以及显示加载. 一.EF Core  1.1 1.当前的版本,还不支持延迟加载(Lazy ...

  10. python 调用阿里云云解析api添加记录

    首先安装阿里云SDK pip install aliyun-python-sdk-core pip install aliyun-python-sdk-alidns 可以配合jenkins传递参数 # ...