题目链接: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. try与catch

    首先要清楚,如果没有try的话,出现异常会导致程序崩溃.而try则可以保证程序的正常运行下去,比如说:try{int i = 1/0;}catch(Exception e){........}一个计算 ...

  2. ibatis中integer类型

    假如java代码中设置的返回类型是integer类型,ibatis实际上返回的是BigDecimal,也就是说  ibatis转换成integer默认是bigdecimal类型的

  3. 在.net4的环境下使用Microsoft.AspNet.SignalR.Client 2.4.0

    我的环境是运行在.net 4 framework,并且使用了signalr 在重连的时候发现,运行的服务被关闭了.找不到合适的处理的办法.因为报错是 说明: 由于未经处理的异常,进程终止.异常信息: ...

  4. hdu4675 GCD of Sequence 莫比乌斯+组合数学

    /** 题目:hdu4675 GCD of Sequence 链接:http://acm.hdu.edu.cn/showproblem.php?pid=4675 题意:给定n个数的a数组,以及m,k: ...

  5. node.js发http请求

    标准库中默认的HTTP模块 const https = require('https'); https.get('https://api.nasa.gov/planetary/apod?api_key ...

  6. php -- PDO属性设置

    设置PDO在处理数据的过程中采用什么方式去处理 PDO::setAttribute:设置属性 PDO::getAttribute:获取属性 语法: bool PDO::setAttribute ( i ...

  7. gitolite 服务器搭建

    网上大牛都说的是安装gitolite要建git用户,我看完全没必要,毕竟用户拿到私钥也未必能登录服务器吧...下面我们就用root用户来安装gitolite,并且配置版本库文件保存路径.. 1. gi ...

  8. layDate/DatePicker日期时间空间

    真心不错,果断收藏了. 1.示例与效果 2.更多示例与皮肤 补充说明:My97DatePicker日期时间插件 的使用 1.示例与效果 2. 更多 常用的实例:WdatePicker下载 http:/ ...

  9. Run time setting设置详解

    Pacing转载自belie 1>     Run time setting设置中的Browser:‘Simulate a new user on each iteration’选项例如:录制了 ...

  10. [Openwrt]wifi桥接设置

    1/连接wifi,用扫描加入,新建一个ingerface  client模式 2/新建wifi ,network选lan和自身新建的interface.此interface设置为bridge模式,连接 ...