题意

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(单调栈)的更多相关文章

  1. 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 ...

  2. 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 ...

  3. set+线段树 Codeforces Round #305 (Div. 2) D. Mike and Feet

    题目传送门 /* 题意:对于长度为x的子序列,每个序列存放为最小值,输出长度为x的子序列的最大值 set+线段树:线段树每个结点存放长度为rt的最大值,更新:先升序排序,逐个添加到set中 查找左右相 ...

  4. 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 ...

  5. 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 ...

  6. 数论/暴力 Codeforces Round #305 (Div. 2) C. Mike and Frog

    题目传送门 /* 数论/暴力:找出第一次到a1,a2的次数,再找到完整周期p1,p2,然后以2*m为范围 t1,t2为各自起点开始“赛跑”,谁落后谁加一个周期,等到t1 == t2结束 详细解释:ht ...

  7. 暴力 Codeforces Round #305 (Div. 2) B. Mike and Fun

    题目传送门 /* 暴力:每次更新该行的num[],然后暴力找出最优解就可以了:) */ #include <cstdio> #include <cstring> #includ ...

  8. 字符串处理 Codeforces Round #305 (Div. 2) A. Mike and Fax

    题目传送门 /* 字符串处理:回文串是串联的,一个一个判断 */ #include <cstdio> #include <cstring> #include <iostr ...

  9. 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 ...

随机推荐

  1. C++学习七 C++实现add(1)(2)(3)

    一.代码实现: class Yoba { public: Yoba(int n) : _n(n) {} Yoba operator() (int n) { return Yoba(_n + n); } ...

  2. CF812C Sagheer and Nubian Market

    CF812C Sagheer and Nubian Market 洛谷评测传送门 题目描述 On his trip to Luxor and Aswan, Sagheer went to a Nubi ...

  3. SpringCloud微服务常见组件理解

    概述 毫无疑问,Spring Cloud是目前微服务架构领域的翘楚,无数的书籍博客都在讲解这个技术.不过大多数讲解还停留在对Spring Cloud功能使用的层面,其底层的很多原理,很多人可能并不知晓 ...

  4. 【笔记】Java微服务之路(持续更新)

    微服务架构的说明: 微服务的架构风格是将一个单体的应用程序开发拆解为一组"小"的服务,这里的"小"是以业务边界 来区分的,而不是根据代码的多少区分.每个服务都运 ...

  5. 获取Kafka每个分区最新Offset的几种方法

    目录 脚本方法 Java 程序 参考资料 脚本方法 ./bin/kafka-run-class.sh kafka.tools.GetOffsetShell --broker-list localhos ...

  6. linux内核参数sysctl.conf,TCP握手ack,洪水攻击syn,超时关闭wait

    题记:优化Linux内核sysctl.conf参数来提高服务器并发处理能力 PS:在服务器硬件资源额定有限的情况下,最大的压榨服务器的性能,提高服务器的并发处理能力,是很多运维技术人员思考的问题.要提 ...

  7. C++:class

    class 类是C++的一个重要概念,也是面向对象的一个重要内容.类的行为类似结构体,但功能比结构体的更强大.类是定义该类对象的一个模板,它告诉我们,一个类应该具有什么内容. 声明.定义 类用关键字c ...

  8. UVA 291 The House Of Santa Claus DFS

    题目: In your childhood you most likely had to solve the riddle of the house of Santa Claus. Do you re ...

  9. PHP高级进阶梳理

    基础篇 1.深入理解计算机系统 2.现代操作系统 3.C程序设计语言 4.C语言数据结构和算法 5.Unix环境高级编程 6.TCP/IP网络通信详解 7.Java面向对象编程 8.Java编程思想 ...

  10. AngleSharp 实战(01)之最简单的示例

    文档地址:https://anglesharp.github.io/docs/Examples.html 直接贴代码了: using System; using System.Linq; using ...