题目链接: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(最值)的更多相关文章

  1. 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 ...

  2. Mike and Feet(CF 547B)

    Mike and Feet time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  3. 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 ...

  4. 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 ...

  5. 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 ...

  6. set+线段树 Codeforces Round #305 (Div. 2) D. Mike and Feet

    题目传送门 /* 题意:对于长度为x的子序列,每个序列存放为最小值,输出长度为x的子序列的最大值 set+线段树:线段树每个结点存放长度为rt的最大值,更新:先升序排序,逐个添加到set中 查找左右相 ...

  7. CF Mike and Feet (求连续区间内长度为i的最小值)单调栈

    Mike and Feet time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  8. Codeforces548D:Mike and Feet(单调栈)

    Mike is the president of country What-The-Fatherland. There are n bears living in this country besid ...

  9. Mike and Feet CodeForces - 548D (单调栈)

    Mike is the president of country What-The-Fatherland. There are n bears living in this country besid ...

  10. 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 ...

随机推荐

  1. iis 导入和导出配置——iis管理

    首先我们打开服务器管理器,一般服务器都在左下角的任务栏中,直接点击即可打开 2 打开WEB服务器(IIS),选择IIS根目录,找到右边的共享管理 3 打开共享管理后,我们在右侧的操作中找到导出配置,选 ...

  2. 第二百七十九节,MySQL数据库-pymysql模块操作数据库

    MySQL数据库-pymysql模块操作数据库 pymysql模块是python操作数据库的一个模块 connect()创建数据库链接,参数是连接数据库需要的连接参数使用方式: 模块名称.connec ...

  3. c#并行扫描端口控制台程序

    static void Main(string[] args) { Console.WriteLine("请输入ip"); string ip = Console.ReadLine ...

  4. ORACLE之常用FAQ V1.0

    [B]第一部分.SQL&PL/SQL[/B][Q]怎么样查询特殊字符,如通配符%与_[A]select * from table where name like 'A\_%' escape ' ...

  5. hdu 4715(打表)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4715 思路:先打个素数表,然后判断一下就可以了. #include<iostream> # ...

  6. Spring Cache 自定义注解

    1.在使用spring cache注解如cacheable.cacheevict.cacheput过程中有一些问题: 比如,我们在查到一个list后,可以将list缓存到一个键对应的区域里:当新增.修 ...

  7. php队列算法[转]

    <?php/*** php队列算法* * Create On 2010-6-4* Author Been* QQ:281443751* Email:binbin1129@126.com**/cl ...

  8. Libcap的简介及安装

    Libpcap 简介 libpcap 是unix/linux 平台下的网络数据包捕获函数包, 大多数网络监控软件都以它为基础. Libpcap 可以在绝大多数类unix 平台下工作. Libpcap  ...

  9. [素数个数模板] HDU 5901 Count primes

    #include<cstdio> #include<cmath> using namespace std; #define LL long long ; bool np[N]; ...

  10. eclipse 的代码着色插件 --Eclipse Color Theme

    Eclipse Color ThemeEclipse自带的背景颜色是白色的,很伤眼睛,故而安装一个颜色和主题插件,来改变代码区域的背景颜色以及关键字的颜色. 网址:http://eclipsecolo ...