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 ...
随机推荐
- Eclipse快捷键大全(转载)
一·eclipse 中的一些常用的快捷键Eclipse的编辑功能非常强大,掌握了Eclipse快捷键功能,能够大大提高开发效率.Eclipse中有如下一些和编辑相关的快捷键. 1. [ALT+/] ...
- ANALYSIS AND EXPLOITATION OF A LINUX KERNEL VULNERABILITY (CVE-2016-0728)
ANALYSIS AND EXPLOITATION OF A LINUX KERNEL VULNERABILITY (CVE-2016-0728) By Perception Point Resear ...
- LeetCode(125)题解--Valid Palindrome
https://leetcode.com/problems/valid-palindrome/ 题目: Given a string, determine if it is a palindrome, ...
- iframe调用父页面js函数 方法 元素
在一个页面中添加iframe,但是有时需要与父页面进行通信,传递参数. 网上总结有以下方法: 一.iframe标签中 src属性传参 <iframe src="test.jsp?i ...
- 有待总结的KMP算法 sdut oj 2463 学密码学一定得学程序
学密码学一定得学程序 Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 曾经,ZYJ同学非常喜欢密码 学.有一天,他发现了一个很长很 ...
- this.triggerEvent()用法
在对组件进行封装时 在当前页面想要获取组件中的某一状态,需要使用到this.triggerEvent(' ',{},{}),第一个参数是自定义事件名称,这个名称是在页面调用组件时bind的名称,第二个 ...
- win10环境变量path误删(windows找不到文件‘%windir%\systempropertiesadvanced.exe’)的解决办法
具体步骤如下:1. 首先重新启动电脑,点击开始按钮,选择电源,此时按住键盘上的shift键,再点击“重启”,选择疑难解答->再选择高级选项->再选择启动设置->然后点击重启-> ...
- !function(){}()和function(){}()区别
控制台打印结果如下所示,接下来看一下具体运行,参考https://swordair.com/function-and-exclamation-mark/: 让一个函数声明语句变成了一个表达式
- [HAOI 2012] Road
[题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=2750 [算法] 考虑计算每个点对每条边的贡献 对于每个点首先运行SPFA或Dijks ...
- 使用PowerDesigner设计数据库
1.快捷键CTRL+N 创建 New Model 选择如下图,并设置 Model name 单击OK 2.使用工具添加实体 双击Entity_1,填上如下图信息 切换选项卡,添加属性信息 其中 M ...