D. Mike and Feet---cf548D(最值)
题目链接: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(最值)的更多相关文章
- 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 ...
- Mike and Feet(CF 547B)
Mike and Feet time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- 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. 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 ...
- set+线段树 Codeforces Round #305 (Div. 2) D. Mike and Feet
题目传送门 /* 题意:对于长度为x的子序列,每个序列存放为最小值,输出长度为x的子序列的最大值 set+线段树:线段树每个结点存放长度为rt的最大值,更新:先升序排序,逐个添加到set中 查找左右相 ...
- CF Mike and Feet (求连续区间内长度为i的最小值)单调栈
Mike and Feet time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- Codeforces548D:Mike and Feet(单调栈)
Mike is the president of country What-The-Fatherland. There are n bears living in this country besid ...
- 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. 1) B. Mike and Feet
Mike is the president of country What-The-Fatherland. There are n bears living in this country besid ...
随机推荐
- UCOS2系统内核讲述(二)_初始化调用函数
Ⅰ.写在前面 学习本文之前可以参看我前面的文章: UCOS2_STM32F1移植详细过程(汇总文章) UCOS2系统内核讲述(一)_总体描述 还是按照上一篇文章的思维(从外到内),本文(结合源代码)进 ...
- 几种在Linux下查询外网IP的办法。
几种在Linux下查询外网IP的办法. Curl 纯文本格式输出: curl icanhazip.com curl ifconfig.me curl curlmyip.com curl ip.ap ...
- html5shiv.js分析-读源码之javascript系列
xiaolingzi 发表于 2012-05-31 23:42:29 首先,我们先了解一下html5shiv.js是什么. html5shiv.js是一套实现让ie低版本等浏览器支持html5标签的解 ...
- C++ 函数的扩展①
//函数扩展--内联函数 inline #include<iostream> using namespace std; /* c++中const常量可以替代宏常数定义 如: const i ...
- 关于Unity5.5中2D动画的制作
1.首先要创建一个精灵 GameProject--2Dproject--Sprite 叫bird 2.给这个精灵附加纹理,并让它显示自己想让它显示的场景层中,一般它的静止纹理就是动画的第一张图片 3. ...
- 采样方法(Sampling Methods)
1.基本采样算法(Basic Sampling Algorithms) 1.1.标准概率分布(Standard distributions) 1.2.拒绝采样(Rejection sampling) ...
- PyQT实现扩展窗口,更多/隐藏
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAVcAAAFeCAIAAAC+XMuHAAAgAElEQVR4nOy9Z5Ac153g2fx0F2fiYi ...
- vue-cli打包构建时常见的报错解决方案
报错1:vue-cli项目本地npm run dev启动后,chrome打开是空白页 解决方案:将config下的index.js中的assetsPublicPath路径都设置为‘/’绝对路径 报错2 ...
- 传递任意数量的实参*parameter&使用任意数量的关键字实参**parameter
1.*形参名(*parameter) 有时候我们不知道知道函数需要接受多少个实参,所以我们可以在形参名前加一个*,是让python创建一个名为parameter的空元组,并将收到的所有值都封装到这个元 ...
- AWS系列-使用Could Events定时对EC2打快照
第1章 使用Could Events定时对EC2打快照 1.1 打开控制台搜索CloudWatch 在搜索栏输入CloudWatch,点击进入CloudWatch控制台 1.2 选择进入Events ...