codeforces 547B. Mike and Feet 单调栈
用单调栈计算出一个数字, 左边第一个比他小的数字的位置, 右边比第一个他小的数字的位置, 然后len = r[i] - l[i] +1. ans[len] = max(ans[len], a[i])
#include<bits/stdc++.h>
using namespace std;
const int maxn = 2e5+;
int l[maxn], r[maxn], ans[maxn], a[maxn], q[maxn];
int main()
{
int n;
cin>>n;
for(int i = ; i<=n; i++) {
scanf("%d", &a[i]);
}
int i = , st = ;
while(i<=n) {
while(st&&a[q[st-]]>a[i]) {
r[q[st-]] = i-;
st--;
}
q[st++] = i;
i++;
}
while(st) {
r[q[st-]] = n;
st--;
}
i = n;
while(i>=) {
while(st&&a[q[st-]]>a[i]) {
l[q[st-]] = i+;
st--;
}
q[st++] = i;
i--;
}
while(st) {
l[q[st-]] = ;
st--;
}
memset(ans, , sizeof(ans));
for(int i = ; i<=n; i++) {
int len = r[i]-l[i]+;
if(ans[len]<a[i]) {
ans[len] = a[i];
}
}
for(i = n; i>=; i--) {
if(ans[i]>=ans[i-])
ans[i-] = ans[i];
}
for(int i = ; i<=n; i++) {
printf("%d ", ans[i]);
}
}
codeforces 547B. Mike and Feet 单调栈的更多相关文章
- Codeforces 547B. Mike and Feet[单调栈/队列]
这道题用单调递增的单调栈维护每个数能够覆盖的最大区间即可. 对于 1 2 3 4 5 4 3 2 1 6 这组样例, 1能够覆盖的最大区间是10,2能够覆盖的最大区间是7,以此类推,我们可以使用单 ...
- 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 单调栈
D. Mike and Feet time limit per test 1 second memory limit per test 256 megabytes input standard inp ...
- Codeforces548D:Mike and Feet(单调栈)
Mike is the president of country What-The-Fatherland. There are n bears living in this country besid ...
- Codeforces 601B. Lipshitz Sequence(单调栈)
Codeforces 601B. Lipshitz Sequence 题意:,q个询问,每次询问给出l,r,求a数组[l,r]中所有子区间的L值的和. 思路:首先要观察到,斜率最大值只会出现在相邻两点 ...
- Codeforces 601B(贪心+斜率+组合数学+单调栈)
题面 传送门 题目大意: L(h)的值是区间[L,R]内,abs(h[i]-h[j])/(i-j)的最大值.现在有q个询问,每个询问表示询问区间[L,R]内,所有子序列的L(h)的值的和 分析 将|h ...
- cf 547B. Mike and Feet dp
题意: n个矩阵排成一排,n<=2e5,高度分别为hei[i],宽度为1 对于一些连续的矩阵,矩阵的size为矩阵的个数,矩阵的strength为这些矩阵中高度最低的那一个高度 求:for ea ...
- Mike and Feet CodeForces - 548D (单调栈)
Mike is the president of country What-The-Fatherland. There are n bears living in this country besid ...
- Codeforces Round #305 (Div. 2)D. Mike and Feet(单调栈)
题意 n个值代表n个熊的高度 对于size为x的group strength值为这个group(连续的几个熊)中熊的最小的height值 对于x(1<=x<=n) 求出最大的strengt ...
随机推荐
- JS原型,Prototype,原型
对于javascript这样一种前端语言,个人觉得,要真正的理解其oop, 就必须要彻底搞清楚javascript的对象,原型链,作用域,闭包,以及this所引用的对象等概念.这些对弄明白了,应该就可 ...
- SqlServer2008 数据库同步的两种方式 (发布、订阅)
尊重原著作:本文转载自http://www.cnblogs.com/tyb1222/archive/2011/05/31/2064944.html 上篇中说了通过SQL JOB的方式对数据库的同步,这 ...
- stat 函数讲解
表头文件: #include <sys/stat.h> #include <unistd.h>定义函数: int stat( ...
- 浅谈C中的指针和数组(一)
本文转载地址:http://www.cnblogs.com/dolphin0520/archive/2011/11/09/2242138.html 在原文的基础上加入自己的想法作为修改. 指针是C/C ...
- python递归函数下不能正常使用yield
# -*- coding:utf-8 -*- import os import time file_list = [] def findFile(path): listFile = os.listdi ...
- ASP.NET页面跳转
总结一下跳转方式: <a>标签 <a href=”home.aspx”></a> HyperLink控件 Asp.net 服务器端控件 属性NavigateUrl指 ...
- c 函数传入数组。
php 里面 直接 count($arr); 一个函数搞定, c里面想判断下数组的个数却非常困难. 想到php是C写的,那看看他的函数怎么写的不就行了... 哦,天啊,,事实比我想的要复杂的多... ...
- c语言中 %p的含义
格式控制符“%p”中的p是pointer(指针)的缩写.指针的值是语言实现(编译程序)相关的,但几乎所有实现中,指针的值都是一个表示地址空间中某个存储器单元的整数.printf函数族中对于%p一般以十 ...
- impala安装
http://blog.sina.com.cn/s/blog_8c6d7ff60101e3lh.html ----------------------------------------------- ...
- 发布MFC ActiveX控件并实现自动更新
一. 引言 上一篇我们讲了如何使用 VC 2005来开发 MFC ActiveX控件,我们开发 ActiveX控件最终目的是将 ActiveX控件发布出来并嵌入在 Web网页中,随着控件 ...