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/problem/B
Description
Mike is the president of country What-The-Fatherland. There are n bears living in this country besides Mike. All of them are standing in a line and they are numbered from 1 to n from left to right. i-th bear is exactly ai feet high.

A group of bears is a non-empty contiguous segment of the line. The size of a group is the number of bears in that group. The strength of a group is the minimum height of the bear in that group.
Mike is a curious to know for each x such that 1 ≤ x ≤ n the maximum strength among all groups of size x.
Input
The first line of input contains integer n (1 ≤ n ≤ 2 × 105), the number of bears.
The second line contains n integers separated by space, a1, a2, ..., an (1 ≤ ai ≤ 109), heights of bears.
Output
Print n integers in one line. For each x from 1 to n, print the maximum strength among all groups of size x.
Sample Input
10
1 2 3 4 5 4 3 2 1 6
Sample Output
6 4 4 3 3 2 2 1 1 1
HINT
题意
给你一个堆数,对于(1,n)长度,让你找到线段的最小值的最大值是多少
题解:
用一个类似单调栈的思想,处理以这个点为最小值可以往左右延伸多少,然后乱搞一下就好了
代码:
//qscqesze
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define test freopen("test.txt","r",stdin)
#define maxn 200001
#define mod 1000000007
#define eps 1e-9
int Num;
char CH[];
//const int inf=0x7fffffff; //нчоч╢С
const int inf=0x3f3f3f3f;
inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
inline void P(int x)
{
Num=;if(!x){putchar('');puts("");return;}
while(x>)CH[++Num]=x%,x/=;
while(Num)putchar(CH[Num--]+);
puts("");
}
//************************************************************************************** int a[maxn];
int dp[maxn];
int l[maxn];
int r[maxn];
int main()
{
//test;
int n=read();
for(int i=;i<=n;i++)
a[i]=read();
a[]=-,a[n+]=-; for(int i=;i<=n;i++)
{
int j=i-;
while(a[j]>=a[i])j=l[j];
l[i]=j;
}
for(int i=n;i>=;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]-;
dp[len]=max(dp[len],a[i]);
}
for(int i=n-;i>=;i--)
dp[i]=max(dp[i+],dp[i]);
for(int i=;i<=n;i++)
cout<<dp[i]<<" ";
}
10
1 2 3 4 5 4 3 2 1 6
Codeforces Round #305 (Div. 1) B. Mike and Feet 单调栈的更多相关文章
- 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中 查找左右相 ...
 - 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. 2)D. Mike and Feet(单调栈)
		
题意 n个值代表n个熊的高度 对于size为x的group strength值为这个group(连续的几个熊)中熊的最小的height值 对于x(1<=x<=n) 求出最大的strengt ...
 - 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 ...
 - 数论/暴力 Codeforces Round #305 (Div. 2) C. Mike and Frog
		
题目传送门 /* 数论/暴力:找出第一次到a1,a2的次数,再找到完整周期p1,p2,然后以2*m为范围 t1,t2为各自起点开始“赛跑”,谁落后谁加一个周期,等到t1 == t2结束 详细解释:ht ...
 - 暴力 Codeforces Round #305 (Div. 2) B. Mike and Fun
		
题目传送门 /* 暴力:每次更新该行的num[],然后暴力找出最优解就可以了:) */ #include <cstdio> #include <cstring> #includ ...
 - 字符串处理 Codeforces Round #305 (Div. 2) A. Mike and Fax
		
题目传送门 /* 字符串处理:回文串是串联的,一个一个判断 */ #include <cstdio> #include <cstring> #include <iostr ...
 - Codeforces Round #305 (Div. 2) B. Mike and Fun 暴力
		
B. Mike and Fun Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/548/pro ...
 
随机推荐
- jquery对象和javascript对象即DOM对象相互转换
			
jquery对象和javascript对象即DOM对象相互转换 1. DOM 对象转成 jQuery 对象对于已经是一个 DOM 对象,只需要用 $() 把DOM对象包装起来,就可以获得一个 jQue ...
 - KKT条件和拉格朗日乘子法详解
			
\(\frac{以梦为马}{晨凫追风}\) 最优化问题的最优性条件,最优化问题的解的必要条件和充分条件 无约束问题的解的必要条件 \(f(x)\)在\(x\)处的梯度向量是0 有约束问题的最优性条件 ...
 - 74.VS2013和opencv3.1.0安装教程
			
一.先下载文件 1.VS2013 VS2013有很多版本,专业版,旗舰版,中文英文之类的,所对应的密钥也不一样.我选择的是简体中文专业版.下载链接如下. http://www.musnow.com/t ...
 - 64_p6
			
polkit-kde-5.10.1-1.fc26.x86_64.rpm 12-Jun-2017 13:45 84854 polkit-libs-0.113-8.fc26.i686.rpm 13-Apr ...
 - C++学习笔记--从虚函数说开去
			
虚函数与纯虚函数: 虚函数:在某基类中声明为virtual并在一个或多个派生类中被重新定义的成员函数,virtual 函数返回类型 函数名(参数表){函数体;} ,实现多态性,通过指向派生类的基类 ...
 - cgi与html相互调用
			
html中调用cgi.<form action="/cgi-bin/mult.cgi" method="get" target="_blank& ...
 - ubuntu包管理命令apt和dpkg的用法
			
apt-get命令: apt-get是debian,ubuntu发行版的包管理工具,与红帽中的yum工具非常类似,适用于deb包管理式的操作系统,主要用于自动从互联网的软件仓库中搜索.安装.升级.卸载 ...
 - 使用gradle建立java application
			
建立项目目录mkdir java-democd java-demo 初始化项目目录gradle init --type java-application 编译./gradlew build 运行./g ...
 - Spark 源码解析:TaskScheduler的任务提交和task最佳位置算法
			
上篇文章< Spark 源码解析 : DAGScheduler中的DAG划分与提交 >介绍了DAGScheduler的Stage划分算法. 本文继续分析Stage被封装成TaskSet, ...
 - vuex 操作姿势
			
Vuex 应用的核心就是 store,它包含着你的应用中大部分的状态 (state) 你不能直接改变 store 中的状态.改变 store 中的状态的唯一途径就是显式地提交 (commit) mut ...