http://codeforces.com/contest/484/problem/E

题意:

给出n个数,查询最大的在区间[l,r]内,长为w的子区间的最小值

第i棵线段树表示>=i的数

维护最长连续子区间

把数从大到小插入主席树

对于每个询问,二分x

在第x棵线段树中查,若最长连续子区间>=w,到代表更大的线段树中查

没有建第n+1棵线段树,导致前面节点的siz不对,WA了一次

#include<cstdio>
#include<iostream>
#include<algorithm>using namespace std;#define N 100001pair<int,int>a[N];int tot;
int root[N+1],lc[N*20],rc[N*20];struct node
{int siz;int mx,lmax,rmax;node operator + (node p){node c;c.siz=siz+p.siz;c.lmax=lmax;if(lmax==siz) c.lmax+=p.lmax;c.rmax=p.rmax;if(p.rmax==p.siz) c.rmax+=rmax;c.mx=max(mx,p.mx);c.mx=max(c.mx,rmax+p.lmax);return c;}}e[N*20];void read(int &x)
{x=0; char c=getchar();while(!isdigit(c)) c=getchar();while(isdigit(c)) { x=x*10+c-'0'; c=getchar(); }
}void build(int &k,int l,int r)
{e[k=++tot].siz=r-l+1;;if(l==r) return;int mid=l+r>>1;build(lc[k],l,mid);build(rc[k],mid+1,r);
}void insert(int pre,int &k,int l,int r,int pos)
{k=++tot;if(l==r){e[k].siz=1;e[k].mx=e[k].lmax=e[k].rmax=1;return;}int mid=l+r>>1;if(pos<=mid) {rc[k]=rc[pre];insert(lc[pre],lc[k],l,mid,pos);}else {lc[k]=lc[pre];insert(rc[pre],rc[k],mid+1,r,pos);}e[k]=e[lc[k]]+e[rc[k]];
}node query(int k,int l,int r,int opl,int opr)
{if(l>=opl && r<=opr) return e[k];int mid=l+r>>1;if(opr<=mid) return query(lc[k],l,mid,opl,opr);if(opl>mid) return query(rc[k],mid+1,r,opl,opr);return query(lc[k],l,mid,opl,opr)+query(rc[k],mid+1,r,opl,opr);
}int main()
{//freopen("data.in","r",stdin);//freopen("my.out","w",stdout);int n;read(n);for(int i=1;i<=n;++i) {read(a[i].first);a[i].second=i;}sort(a+1,a+n+1);build(root[n+1],1,n);for(int i=n;i;--i) insert(root[i+1],root[i],1,n,a[i].second);int m;read(m);int s,t,w;int l,r,mid;int ans;while(m--){read(s); read(t); read(w);l=1,r=n; ans=0;while(l<=r){mid=l+r>>1;if(query(root[mid],1,n,s,t).mx>=w)  ans=mid,l=mid+1;else r=mid-1;}cout<<a[ans].first<<'\n';}
}

E. Sign on Fence
time limit per test

4 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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:

  1. The width of the sign should be exactly w meters.
  2. 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.

Input

The first line of the input contains integer n — the number of panels in the fence (1 ≤ n ≤ 105).

The second line contains n space-separated integers hi, — the heights of the panels (1 ≤ hi ≤ 109).

The third line contains an integer m — the number of the queries (1 ≤ m ≤ 105).

The next m lines contain the descriptions of the queries, each query is represented by three integers lr and w (1 ≤ l ≤ r ≤ n,1 ≤ w ≤ r - l + 1) — the segment of the fence and the width of the sign respectively.

Output

For each query print the answer on a separate line — the maximum height of the sign that can be put in the corresponding segment of the fence with all the conditions being satisfied.

Examples
input
51 2 2 3 332 5 32 5 21 5 5

output
231

Note

The fence described in the sample looks as follows:

The possible positions for the signs for all queries are given below.

The optimal position of the sign for the first query.The optimal position of the sign for the second query.The optimal position of the sign for the third query.

转载于:https://www.cnblogs.com/TheRoadToTheGold/p/8194482.html

CFCC百套计划4 Codeforces Round #276 (Div. 1) E. Sign on Fence相关推荐

  1. CFCC百套计划2 CodeChef December Challenge 2017 Chef And Easy Xor Queries

    https://www.codechef.com/DEC17/problems/CHEFEXQ 题意: 位置i的数改为k 询问区间[1,i]内有多少个前缀的异或和为k 分块 sum[i][j] 表示第 ...

  2. szu cf套题训练Codeforces Round #602 (Div. 2, based on Technocup 2020 Elimination Round 3)A~D题解报告

    A. Math Problem 题目大意:就是给你n个线段,你自己再添加一个线段d使得d和所有的线段都有交点,求d这个线段的最小长度是多少 解题思路: 1.首先看d线段的左端点,就是左端点选取的是所有 ...

  3. Codeforces Round #276 (Div. 2)

    A. Factory 题意:给出a,m,第一天的总量为a,需要生产为a%m,第二天的总量为a+a%m,需要生产(a+a%m)%m 计算到哪一天a%m==0为止 自己做的时候,把i开到1000来循环就过 ...

  4. 【瞎搞】 Codeforces Round 276 DIV 2 C.Bits

    求L-R 区间内的X的二进制中1 最多的个数 当前 L 为 popcount(L) 中最小的 每次从低到高 在 L为0 的位置上添上1  保证了值的最小 #include <cstdio> ...

  5. Codeforces Round #701 (Div. 2) A ~ F ,6题全,超高质量良心题解【每日亿题】2021/2/13

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 目录 A - Add and Divide B - Replace and Keep Sorted C ...

  6. Codeforces Round #699 (Div. 2) (A ~ F)6题全,超高质量良心题解【每日亿题】2021/2/6

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 Codeforces Round #699 (Div. 2) (A.B.C)[每日亿题]2021/2/ ...

  7. Codeforces Round #698 (Div. 2)(A ~ F)6题全,超高质量题解)【每日亿题】2021/2/4

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 目录 [每日亿题]Codeforces Round #698 (Div. 2)(A ~ F)6题全,超 ...

  8. Codeforces Round #694 (Div. 1 + Div2)(A ~ H,8题全,超高质量题解)【每日亿题】2021/2/1、2/2

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 目录 [每日亿题]Codeforces Round #694 (Div. 1 + Div2)(A ~ ...

  9. Codeforces Round #696 (Div. 2) (A ~ E)超高质量题解(每日训练 Day.16 )

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 Codeforces Round #696 (Div. 2) (A ~ E)超高质量题解 比赛链接:h ...

最新文章

  1. python3 matlabplot 和numpy 简单绘图
  2. java左移、右移、无符号右移
  3. 点击ride界面edit空白_『技术锦囊』如何在SOLIDWORKS界面调用宏程序?
  4. jpa和hibernate_从JPA到Hibernate的旧版和增强型标识符生成器
  5. Kafka学习之四 Kafka常用命令
  6. 习题3.11 递归和非递归查找元素
  7. 线性回归(单神经元,多神经元)和多层感知机(多个神经元)对比
  8. 协鑫集成为泰国Enmax建立10MW光伏电站
  9. 全文搜索引擎的比较-Lucene,Sphinx,Postgresql,MySQL?
  10. 小学生都能听懂的傅里叶变换讲解
  11. CenterNet++ | CenterNet携手CornerNet终于杀回来了,实时高精度检测值得拥有!
  12. HttpClient模拟客户端请求实例
  13. postman脚本文件存放的地址
  14. 对“回调函数”的理解
  15. 2022021第二届青少年计算机知识竞赛
  16. “卖惨”的悲情牌打多了,营销终将变“悲剧”
  17. 阿里云天池机器学习task3
  18. 软件架构图——RUP4+1架构方法
  19. 软件推荐:强力卸载软件HIBIT
  20. notepad++设置背景颜色为豆沙绿

热门文章

  1. 段错误linux 内存不够,c - 为什么我的程序在linux-gcc而不是mingw-gcc上出现段错误? - 堆栈内存溢出...
  2. unity连接linux服务器,C#编程之C#通过SharpSSH库与Linux服务器建立SSH连接并执行命令...
  3. php get安全字符,php安全之直接用$获取值而不$_GET 字符转义
  4. php 定义数组使用逗号,
  5. yii2.0框架中自定义接口,实现类的多继承
  6. java类中的代码块,Java开发避坑指南!
  7. Android面试真题解析火爆全网,薪资翻倍
  8. 【深度学习】Keras加载权重更新模型训练的教程(MobileNet)
  9. 【深度学习】Transfomer在文本处理上的应用(风格识别)
  10. 算法训练 连续正整数的和 (枚举)