D. Mike and Feet---cf548D(最值)
题目链接:http://codeforces.com/problemset/problem/548/D
给你n个数,对于(1,n)长度,让你找到线段的最小值的最大值是多少
#include<iostream>
#include<cstring>
#include<cstdio>
#include<queue>
#include<algorithm>
#define N 200050
#define INF 1e16
#define met(a, b) memset(a, b, sizeof(a))
using namespace std;
typedef long long LL; int a[N], ans[N], n, L[N], R[N]; int main()
{
while(scanf("%d", &n)!=EOF)
{
a[]=-, a[n+]=-;
for(int i=; i<=n; i++)
scanf("%d", &a[i]); for(int i=; i<=n; i++)///以a[i]为最小值的左边界;
{
int j = i-;
while(a[j]>=a[i])j=L[j];
L[i] = j;
} for(int i=n; i>=; i--)///以a[i]为最小值的右边界;
{
int j=i+;
while(a[j]>=a[i])j=R[j];
R[i] = j;
}
for(int i=; i<=n; i++)
{
int len=R[i]-L[i]-;
ans[len]=max(ans[len], a[i]);///ans[len]表示长度为len的最小值,和当前的a[i]取最小值;
}
for(int i=n-; i>=; i--)///更新未更新的值;
ans[i]=max(ans[i], ans[i+]);
for(int i=; i<=n; i++)
printf("%d%c", ans[i], i==n?'\n':' ');
}
return ;
}
D. Mike and Feet---cf548D(最值)的更多相关文章
- CF #305(Div.2) D. Mike and Feet(数学推导)
D. Mike and Feet time limit per test 1 second memory limit per test 256 megabytes input standard inp ...
- Mike and Feet(CF 547B)
Mike and Feet time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- Codeforces Round #305 (Div. 2) D. Mike and Feet 单调栈
D. Mike and Feet time limit per test 1 second memory limit per test 256 megabytes input standard inp ...
- Codeforces Round #305 (Div. 1) B. Mike and Feet 单调栈
B. Mike and Feet Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/547/pro ...
- Codeforces Round #305 (Div. 2) D. Mike and Feet
D. Mike and Feet time limit per test 1 second memory limit per test 256 megabytes input standard inp ...
- set+线段树 Codeforces Round #305 (Div. 2) D. Mike and Feet
题目传送门 /* 题意:对于长度为x的子序列,每个序列存放为最小值,输出长度为x的子序列的最大值 set+线段树:线段树每个结点存放长度为rt的最大值,更新:先升序排序,逐个添加到set中 查找左右相 ...
- CF Mike and Feet (求连续区间内长度为i的最小值)单调栈
Mike and Feet time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- Codeforces548D:Mike and Feet(单调栈)
Mike is the president of country What-The-Fatherland. There are n bears living in this country besid ...
- Mike and Feet CodeForces - 548D (单调栈)
Mike is the president of country What-The-Fatherland. There are n bears living in this country besid ...
- Codeforces Round #305 (Div. 1) B. Mike and Feet
Mike is the president of country What-The-Fatherland. There are n bears living in this country besid ...
随机推荐
- jar 打包命令详解
原文: https://blog.csdn.net/marryshi/article/details/50751764 本文详细讲述了JAR命令的用法,对于大家学习和总结jar命令的使用有一定的帮助作 ...
- java常用操作
1.properties文件中文转换 在cmd中进入到文件所在目录执行(其他操作请见命令帮助):native2ascii -reverse messages_zh_CN.properties b.t ...
- 关于Netfilter NF_HOOK宏的outdev參数bug
1.首先指出.NF_HOOK系列宏的outdev參数的传递方式(直接传递一个net_device结构体指针)是不对的 正确的方式要么是不传递.要么是传递指针的地址,即地址的地址. 2.接下来指出,仅仅 ...
- Unix系统编程()改变信号处置:signal
Unix系统提供了两种方法来改变信号处置:signal和sigaction.这篇描述的是signal系统调用,是设置信号处理的原始API,所提供的接口比sigaction简单.另一方面,sigacti ...
- alsamixer + alsactl 控制放音通道
1 使用alsamixer的gui界面配置放音(控制OUT1,OUT2的音量); 2 退出alsamixer,使用alsactl store生成配置文件,文件位于/etc/asound.state; ...
- Android——Android Bundle类(转)
今天发现自己连Bundle类都没有搞清楚,于是花时间研究了一下. 根据google官方的文档(http://developer.android.com/reference/android/os/Bun ...
- Java,Mysql-根据一个给定经纬度的点,进行附近500米地点查询–合理利用算法
Java,Mysql-根据一个给定经纬度的点,进行附近500米地点查询–合理利用算法 LBS 球面距离公式 http://wiki.myoa.info/zh-blog:20 Java,Mysql- ...
- Spring MVC属于SpringFrameWork的后续产品
Spring MVC属于SpringFrameWork的后续产品,已经融合在Spring Web Flow里面.Spring MVC 分离了控制器.模型对象.分派器以及处理程序对象的角色,这种分离让它 ...
- 关于Spring MVC Controller 层的单元测试
关于Spring MVC Controller 层的单元测试 测试准备工作: 1.搭建测试Web环境 2.注入Controller 类 3.编写测试数据 测试数据的文件名一定要与测试类的文件名相同,比 ...
- WHERE 子句用于规定选择的标准。
WHERE 子句 如需有条件地从表中选取数据,可将 WHERE 子句添加到 SELECT 语句. 语法 SELECT 列名称 FROM 表名称 WHERE 列 运算符 值 下面的运算符可在 WHERE ...