题意

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. Vue项目开发前的准备工作,node的安装,vue-cli的安装

    一.安装node 1-  点击这里进入node官网下载 2- 3- 下载完成是这样的 4-  双击打开进行安装,一路next,安装完成是这样 5-  打开cmd进入安装node的文件夹,输入node ...

  2. C++ 学习六 operator关键字(重载)

    转载:http://blog.sina.com.cn/s/blog_4b3c1f950100kker.html operator是C++的关键字,它和运算符一起使用,表示一个运算符函数,理解时应将 o ...

  3. lua 5 流程控制 if

    条件判断中,0 表示 true,只有 nil 才是 false if(0) then -- 可以没有括号 print("0 为 true") elseif 1 then print ...

  4. django内容回顾:

    Django 下载安装 命令行 pip install django==1.11.26 -i 源 pycharm 创建项目 命令行 django-admin startproject 项目名 pych ...

  5. 突然看到原来除了jar包还有war包啊?????

    先来说说区别: 首先,jar包呢,是一个压缩文件,可以由很多文件压缩而成,,简单来说就是,jar包是别人写好的一些类,然后对这些类 进行打包,这就是jar包,你可以直接用这些  jar包,使用里面的类 ...

  6. FFT_应用和例题

    卷积 现有两个定义在 N 上的函数 \(f(n),g(n)\),定义 \(f\) 和 \(g\) 的卷积(convolution)为 \(f \otimes g\) \[ (f \otimes g)( ...

  7. Nginx+Tomcat+Memcache 实现session共享

    Nginx + Tomcat + Memcache 实现session共享 1. Nginx 部署 1.上传源码包到服务器,解压安装 下载地址:http://nginx.org/en/download ...

  8. 为什么Linux 普通用户在虚拟机界面可以reboot 用ssh 不能reboot

    应该是有 类似的权限控制. 如果是 localhost , 那么普通用户允许重启. 如果不是localhost,  比如ssh远程的,必须验证root权限.

  9. 一篇文章帮你彻底搞清楚“I/O多路复用”和“异步I/O”的前世今生

    在网络的初期,网民很少,服务器完全无压力,那时的技术也没有现在先进,通常用一个线程来全程跟踪处理一个请求.因为这样最简单. 其实代码实现大家都知道,就是服务器上有个ServerSocket在某个端口监 ...

  10. 使用 jQuery.TypeAhead 让文本框自动完成 (二)(访问远程数据)

    项目地址:https://github.com/twitter/typeahead.js 直接贴代码了: @section headSection { <script type="te ...