题目链接: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. Linux Ubuntu 打开.exe文件

    这两天在编译Android源码,进行到要在Linux里安装烧录软件那一步,要先装驱动,故了解了如何在linux下打开.exe文件. .exe 文件在linux下不能直接打开,可有两种方式打开:. 1. ...

  2. 方程式漏洞之复现window2008/win7 远程命令执行漏洞

    前几天就想写的,因为一些缘故就没写.此次是在外网环境下进行的.大家在内网中也一个样. 方法: 使用Eternalblue模块,剑测是否有漏洞然后msf生成一个dll直接反弹shell. PS:win版 ...

  3. 【BZOJ】1684: [Usaco2005 Oct]Close Encounter(暴力+c++)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1684 这货完全在考精度啊.. 比如奇葩 (llf)a/b*i (llf)(a/b*i)和(llf)( ...

  4. Think Python: How to Think Like a Computer Scientist

    Think Python: How to Think Like a Computer Scientist:http://greenteapress.com/thinkpython/html/index ...

  5. ThinkPHP项目笔记之RBAC(权限)基础篇

    今天,总结一下,RBAC(基于角色的访问控制),直白一点,就是权限管理.说到这,不得不“小叙”一下,我第一次 开发权限管理功能的“插曲”.第一次做这个,真的不会,我只知道“有点印象”,当时任务落到我的 ...

  6. 判断ActiveX控件是Desgin Mode还是Runtime Mode

    对于MFC COleControl::AmbientUserMode Determines if the Container is in design mode or user mode. BOOL ...

  7. C++之运行时类型识别RTTI

     C++ Code  12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 ...

  8. Nuget包制作最佳解决方案

    https://www.cnblogs.com/drea/p/8418717.html 最近研究ABP框架,下载其全套源码,想“据为己有”,这样添加功能或者修改源码的话就非常方便了,否则搭建项目直接用 ...

  9. Linq------错误: Unable to determine the principal end of an association between the types

    [Table("bma_stores")] public class Store { //加上即可 [Required] public virtual Product Produc ...

  10. Hibernate_day02--Hibernate的一级缓存

    Hibernate的一级缓存 什么是缓存 1 数据存到数据库里面,数据库本身是文件系统,使用流方式操作文件效率不是很高. (1)把数据存到内存里面,不需要使用流方式,可以直接读取内存中数据 (2)把数 ...