Codeforces Round #305 (Div. 2) D 维护单调栈
1 second
256 megabytes
standard input
standard output
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.
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.
Print n integers in one line. For each x from 1 to n, print the maximum strength among all groups of size x.
10
1 2 3 4 5 4 3 2 1 6
6 4 4 3 3 2 2 1 1 1
题意:给你一个长度为n的数列 求长度为x x取值(1,n) 的区段最小值的最大值
题解:求以a[i]为最小值的区段的左界右界;
dp[r[i]-l[i]+1]=max(dp[r[i]-l[i]+1],a[i]) 倒序取max得到每个长度的答案;
#pragma comment(linker, "/STACK:102400000,102400000")
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <cctype>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <string>
#include <complex>
#define ll long long
#define mod 1000000007
using namespace std;
int n;
int a[];
int l[];
int r[];
int ans[];
int dp[];
int main()
{
scanf("%d",&n);
for(int i=;i<=n;i++)
scanf("%d",&a[i]);
a[]=-;
a[n+]=-;
l[]=;
for(int i=; i<=n; i++) //关键********
{
int temp=i-;
while(a[temp]>=a[i])//维护一个递增的序列
temp=l[temp]-;
l[i]=temp+;
}
r[n]=n;
for (int i=n-; i>=; i--)
{
int temp=i+;
while(a[temp]>=a[i])
temp=r[temp]+;
r[i]=temp-;
}
for(int i=;i<=n;i++)
dp[r[i]-l[i]+]=max(dp[r[i]-l[i]+],a[i]);
int res=;
for(int i=n;i>=;i--){
res=max(res,dp[i]);
ans[i]=res;
}
for(int i=;i<=n;i++)
printf("%d ",ans[i]);
return ;
}
Codeforces Round #305 (Div. 2) D 维护单调栈的更多相关文章
- Codeforces Round #622 (Div. 2)C(单调栈,DP)
构造出的结果一定是一个单峰/\这种样子的 #define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> using namespace std; ...
- set+线段树 Codeforces Round #305 (Div. 2) D. Mike and Feet
题目传送门 /* 题意:对于长度为x的子序列,每个序列存放为最小值,输出长度为x的子序列的最大值 set+线段树:线段树每个结点存放长度为rt的最大值,更新:先升序排序,逐个添加到set中 查找左右相 ...
- 数论/暴力 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. 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(单调栈)
题意 n个值代表n个熊的高度 对于size为x的group strength值为这个group(连续的几个熊)中熊的最小的height值 对于x(1<=x<=n) 求出最大的strengt ...
- 「日常训练」Mike and Feet(Codeforces Round #305 Div. 2 D)
题意 (Codeforces 548D) 对一个有$n$个数的数列,我们要求其连续$x(1\le x\le n)$(对于每个$x$,这样的连续group有若干个)的最小数的最大值. 分析 这是一道用了 ...
- 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 ...
随机推荐
- Python基础入门(迭代器和生成器)
1 Python迭代器 迭代器是一个可以记住遍历的位置的对象. 迭代器对象从集合的第一个元素开始访问,直到所有的元素被访问完结束. 迭代器只能往前不会后退. 迭代器有两个基本的方法:iter() 和 ...
- Hive中使用sql的注意事项
一.别名的使用 定义别名:columnA as X 不需要使用单引号 使用别名:不与where同时使用 花式报错-->有说hive不支持where后使用别名 二.GROUP BY select ...
- Python基础灬函数(定义,参数)
函数 函数定义 # 定义一个计算绝对值的函数 def cal_abs(x): if x >= 0: return x else: return -x # 调用函数 print('-1的绝对值是: ...
- PHP使用static关键字声明静态属性和静态方法
PHP使用static关键字声明静态属性和静态方法 在PHP中,通过static关键字修饰的成员属性和成员方法被称为静态属性和静态方法. 静态属性和静态方法不需要在被类实例化的情况下就可以直接使用. ...
- Python爬虫入门(5):URLError异常处理
大家好,本节在这里主要说的是URLError还有HTTPError,以及对它们的一些处理. 1.URLError 首先解释下URLError可能产生的原因: 网络无连接,即本机无法上网 连接不到特定的 ...
- 团队作业——王者光耀:team
光耀101 <光耀101>是福州大学数计学院计算机专业推出的中国首部程序猿脱发养成节目.由张栋担任发起人,刘晨瑶.畅畅担任导师. 该节目召集了你猜多少位选手,通过任务.训练.考核,让选 ...
- FivePlus——分工理解
最终的游戏方案 游戏采用回合制,每回合双方英雄各自轮流选择移动和攻击以及大招,选择结束进行结算 英雄/小兵/塔的攻击力/大招效果参照作业要求,如果发现不均衡再进行调整 UI界面考虑使用QT或者命令行界 ...
- 软工1816 · Alpha冲刺(7/10)
团队信息 队名:爸爸饿了 组长博客:here 作业博客:here 组员情况 组员1(组长):王彬 过去两天完成了哪些任务 学会了POSTMAN的使用,对后端已经完成的接口进行了收发消息正确性的验证 推 ...
- 福大软工1816:Beta(4/7)
Beta 冲刺 (1/7) 队名:第三视角 组长博客链接 本次作业链接 团队部分 团队燃尽图 工作情况汇报 张扬(组长) 过去两天完成了哪些任务 文字/口头描述 准备四六级 展示GitHub当日代码/ ...
- 结对编程——paperOne基于java web的简易四则运算出题网站
项目成员:张金生 张政 需求分析: 1.要进行四则运算: 2.运算题目随机: 3.进行对错判断: 4.整数运算. 程序概要: 1.用JSP实现: 2.用户可选择题目数量: 3.答题页用表格列出 ...