Codeforces Round #305 (Div. 2)D. Mike and Feet(单调栈)
题意
n个值代表n个熊的高度 对于size为x的group strength值为这个group(连续的几个熊)中熊的最小的height值
对于x(1<=x<=n) 求出最大的strength值
http://codeforces.com/contest/548/problem/D
思路
我们把每个数作为最小值能最远向左和右用单调栈处理出来,那么可以发现对于x长度的所有group,某个数延伸的区间长度如果大于等于x,则这个数对答案有贡献。
对于样例,我们处理出来后可以观察发现确有此规律:

然后就可以搞啦~
代码
#include<bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
#define ll long long
const int N=200005;
const int mod=1e9+7;
const double eps=1e-8;
const double PI = acos(-1.0);
#define lowbit(x) (x&(-x))
int g[N],L[N],R[N],a[N],h[N],mx[N];
int main()
{
std::ios::sync_with_stdio(false);
int n;
scanf("%d",&n);
for(int i=1; i<=n; i++)
scanf("%d",&a[i]);
a[n+1]=-1;
stack<int> st;
for(int i=1; i<=n; i++)
{
while(!st.empty()&&a[i]<=a[st.top()])
{
st.pop();
}
if(st.empty())
{
L[i]=1;
}
else
{
L[i]=st.top()+1;
}
st.push(i);
}
while(!st.empty()) st.pop();
for(int i=n; i>=1; i--)
{
while(!st.empty()&&a[i]<=a[st.top()])
st.pop();
if(st.empty())
{
R[i]=n;
}
else
R[i]=st.top()-1;
st.push(i);
}
/* for(int i=1; i<=n; i++)
{
cout<<L[i]<<" "<<R[i]<<" "<<endl;
}
cout<<endl;*/
for(int i=1; i<=n; i++)
h[R[i]-L[i]+1]=max(h[R[i]-L[i]+1],a[i]);
for(int i=n;i>=1;i--)
mx[i]=max(mx[i+1],h[i]);
for(int i=1;i<=n;i++)
{
printf("%d ",mx[i]);
}
puts("");
return 0;
}
Codeforces Round #305 (Div. 2)D. Mike and Feet(单调栈)的更多相关文章
- 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中 查找左右相 ...
- 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
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 ...
随机推荐
- node.js中pm2启动应用出错
在将公司的应用容器化时,遇到的问题. 之前,同事使用node.js 6版本运行,pm2启动js文件,一切正常. 但我一样将node.js 6版本安装,然后npm install pm2完成. 运行pm ...
- 4.Python网络编程_一般多线程创建步骤
#该程序使用命令行执行,IDE执行会有其他线程附加 import threading import time #初始化一个线程 #t=threading.Thread(target=func) #fu ...
- idea插件(mybatis框架下mapper接口快速跳转对应xml文件)亲测好用!
我相信目前在绝大部分公司里,主要使用的框架是S(spring)S(spring MVC)M(mybatis),其中mybatis总体架构是编写mapper接口,框架扫描其对应的mapper.xml文件 ...
- CF1225C p-binary
CF1225C p-binary 洛谷评测传送门 题目描述 Vasya will fancy any number as long as it is an integer power of two. ...
- ionic4打包和ngix配置
ionic4打包 ng run app:build --base-href=/edu/course/mobile压缩打包 ng run app:build:production --base-href ...
- NOIP模拟赛2(two)
题目描述 Description 很久很久很久以前,方方方造了一台计算机,计算机中开始有一个数 \(0\) .方方方想要让这个数变成 \(a\) ,他打算每次选择一个整数,把计算机中当前的数按位或上这 ...
- python 机器学习基础教程——第一章,引言
https://www.cnblogs.com/HolyShine/p/10819831.html # from sklearn.datasets import load_iris import nu ...
- 为什么我会选择走 Java 这条路?
本系列文章将整理到我在GitHub上的<Java面试指南>仓库,更多精彩内容请到我的仓库里查看 https://github.com/h2pl/Java-Tutorial 喜欢的话麻烦点 ...
- 【SpringCloud之pigx框架学习之路 】2.部署环境
[SpringCloud之pigx框架学习之路 ]1.基础环境安装 [SpringCloud之pigx框架学习之路 ]2.部署环境 1.下载代码 git clone https://git.pig4c ...
- BFS(四):搜索状态判重
在采用广度优先算法进行搜索时,一个需要重点注意的是在搜索过程中判重和去重.前面介绍的几个例子中,判重都较简单,如采用vis[]数组,若vis[i]==0,则i未访问过,i入队列:若vis[i]!=0, ...