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 ...
随机推荐
- Maximum & Minimum Depth of Binary Tree
Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the long ...
- PHP基础示例:商品信息管理系统v1.1
实现目标:使用php和mysql写一个商品信息管理系统,并带有购物车功能 一.创建数据库和表 1.创建数据库和表:demodb 2.创建表格:goods 字段:商品编号,商品名称,商品类型,商品图片, ...
- js获取当前url参数的两方式
方法一:正则分析法function getQueryString(name) { var reg = new RegExp("(^|&)" + name + &quo ...
- 管理node_modules
http://stackoverflow.com/questions/15225865/centralise-node-modules-in-project-with-subproject
- ajax防止重复提交请求1
ajax防止重复提交请求 A. 独占型提交 只允许同时存在一次提交操作,并且直到本次提交完成才能进行下一次提交. module.submit = function() { if (this.pro ...
- Hibernate之总结
以前做.net,最近做java项目,负责服务端的开发,直接用的jdbc,线程安全问题.缓存同步问题以及连接池什么的,都是手动写,不但麻烦而且容易出错.项目结束,赶快抽时间学了下hibernate,每天 ...
- CC++初学者编程教程(2) Microsoft Visual C++ 6.0开发环境搭建
上一篇演示的是如何安装VS2010,本文演示的是如何安装Microsoft Visual C++ 6.0 简称VC6. 有同学经常VC6都是很古董的版本了,为啥他还存在,不得不说VC6是微软一个很经典 ...
- 一个在mac上编译c++程序的低级失误
今天在编译hadoop的pipes的wordcount例子时,总是报错不能成功. g++ -m64 -I/Users/stephen/Downloads/hadoop-0.20.2/c++/Mac_O ...
- poj2000---和1969一样的模板
#include <stdio.h> #include <stdlib.h> int main() { int d; while(scanf("%d",&a ...
- spoj 7258 Lexicographical Substring Search (后缀自动机)
spoj 7258 Lexicographical Substring Search (后缀自动机) 题意:给出一个字符串,长度为90000.询问q次,每次回答一个k,求字典序第k小的子串. 解题思路 ...