Lightoj1083【单调栈】
#include <cstdio>
#include <stack>
#include <iostream>
#include <string.h>
#include <algorithm>
using namespace std;
typedef long long LL;
const int N=5e4+10;
struct asd
{
LL pre;
LL next;
LL num;
};
int n;
LL ww[N]; int main()
{
int T,cas=1;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
for(int i=1; i<=n; i++)
scanf("%lld",&ww[i]); stack<asd>q;
asd tmp;
tmp.num=ww[1];
tmp.next=tmp.pre=1;
q.push(tmp);
LL ans=0;
for(int i=2; i<=n; i++)
{
asd tmp1;
tmp1.num=ww[i];
tmp1.pre=tmp1.next=1;
while(!q.empty()&&tmp1.num<q.top().num)
{
tmp=q.top();
q.pop();
tmp1.pre+=tmp.pre;
if(!q.empty())
q.top().next+=tmp.next;
ans=max(tmp.num*(tmp.pre+tmp.next-1),ans);
}
q.push(tmp1);
} while(!q.empty())
{
tmp=q.top();
q.pop();
if(!q.empty())
q.top().next+=tmp.next;
ans=max(ans,(tmp.next+tmp.pre-1)*tmp.num);
} printf("Case %d: %lld\n",cas++,ans);
}
return 0;
}
Lightoj1083【单调栈】的更多相关文章
- BZOJ1012: [JSOI2008]最大数maxnumber [线段树 | 单调栈+二分]
1012: [JSOI2008]最大数maxnumber Time Limit: 3 Sec Memory Limit: 162 MBSubmit: 8748 Solved: 3835[Submi ...
- BZOJ 4453: cys就是要拿英魂![后缀数组 ST表 单调栈类似物]
4453: cys就是要拿英魂! Time Limit: 3 Sec Memory Limit: 128 MBSubmit: 90 Solved: 46[Submit][Status][Discu ...
- BZOJ 3238: [Ahoi2013]差异 [后缀数组 单调栈]
3238: [Ahoi2013]差异 Time Limit: 20 Sec Memory Limit: 512 MBSubmit: 2326 Solved: 1054[Submit][Status ...
- poj 2559 Largest Rectangle in a Histogram - 单调栈
Largest Rectangle in a Histogram Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 19782 ...
- bzoj1510: [POI2006]Kra-The Disks(单调栈)
这道题可以O(n)解决,用二分还更慢一点 维护一个单调栈,模拟掉盘子的过程就行了 #include<stdio.h> #include<string.h> #include&l ...
- BZOJ1057[ZJOI2007]棋盘制作 [单调栈]
题目描述 国际象棋是世界上最古老的博弈游戏之一,和中国的围棋.象棋以及日本的将棋同享盛名.据说国际象棋起源于易经的思想,棋盘是一个8*8大小的黑白相间的方阵,对应八八六十四卦,黑白对应阴阳. 而我们的 ...
- 洛谷U4859matrix[单调栈]
题目描述 给一个元素均为正整数的矩阵,上升矩阵的定义为矩阵中每行.每列都是严格递增的. 求给定矩阵中上升子矩阵的数量. 输入输出格式 输入格式: 第一行两个正整数n.m,表示矩阵的行数.列数. 接下来 ...
- POJ3250[USACO2006Nov]Bad Hair Day[单调栈]
Bad Hair Day Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 17774 Accepted: 6000 Des ...
- CodeForces 548D 单调栈
Mike and Feet Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Subm ...
- Gym 101102D---Rectangles(单调栈)
题目链接 http://codeforces.com/gym/101102/problem/D problem description Given an R×C grid with each cel ...
随机推荐
- Spring Cloud Config的配置中心获取不到最新配置信息的问题
Spring Cloud Config的配置中心获取不到最新配置信息的问题 http://blog.didispace.com/spring-cloud-tips-config-tmp-clear/
- 多媒体开发之编码gop---什么是GOP
所谓GOP,意思是画面组,MPEG格中的帧序列,分为I.P.B三种,如排成IBBPBBPBBPBBPBBP...样式,这种连续的帧图片组合即为GOP(画面群,GROUP OF PICTURE),是MP ...
- EasyDarwin开源流媒体服务器实现RTSP直播同步输出MP4、RTMP、HLS的方案思路
背景 近期跟开源团队商量,想在EasyDarwin上继续做一些功能扩展,目前EasyDarwin开源流媒体服务器只能够实现高效的RTSP推流直播转发/分发功能,输入与输出都是RTSP/RTP流,不能够 ...
- Hibernate中的Sesson操作
一.Session概述 Session是应用程序与数据库之间的一个会话,是Hibernate运作的中心,持久层操作的基础,相当于JDBC中的Connection.Session对象是通过Session ...
- A Short Introduction to Boosting
http://www.site.uottawa.ca/~stan/csi5387/boost-tut-ppr.pdf Boosting is a general method for improvin ...
- SVN在myeclipse中新建地址的时出现被拒绝
新建资源库地址: 控制台提示信息: svn: connection refused by the server svn: connection refused by the server Connec ...
- 3个CCIE考官对一个高级工程师的面试题
3个CCIE考官对一个高级工程师的面试题 转载 时间:2015-7-10 原文转载: 1.现在的6509及7609,SUP720交换带宽去到720G,是不是可以说7609/6509 可以取代一部分GS ...
- zabbix 用户自定义监控参数添加
1. item key的添加 key可以带参数,该参数为一个数组列表,可以同时传递多个参数,key的格式如下 key -- [ parameters] -- 例如: vfs.fs.size[/] v ...
- Sublime Text 快捷键及使用技巧的学习整理
下载和安装(很简单,省略)下载地址 http://www.sublimetext.com/2 1. 有两点需要注意 a) Sublime Text目前稳定的版本是Sublime Text 2,Subl ...
- SPOJ MAXOR (分块 || 可持久化字典树 || 异或)(好题)
You are given a sequence A[1], A[2], ..., A[N]. (0 ≤ A[i] < 231, 1 ≤ N ≤ 12000). A query is defin ...