Lightoj1083【单调栈】
2024-10-19 14:35:23
#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;
}
最新文章
- [Copy]Bird&#39;s booklist
- 快速破解哈希密文findmyhash
- 同网段下,windows自带远程桌面连接
- mysql 修改字符集
- X光机的原理及构造
- js中的屏蔽
- Storm官方文档翻译之创建Storm项目
- jq获取被选中的option的值。jq获取被选中的单选按钮radio的值。
- VS2015远程调试
- Swift基础之init方法,实例方法,类方法(静态方法)的使用(多标签Demo)
- vscode中vue代码颜色插件
- Linux内核分析第七次作业
- MySQL中MyISAM与InnoDB区别及选择
- CSS之透视perspective属性
- Learning to rank相关的pointwise,pairwise,listwise
- 进度条ProgressBar
- 【PAT Advanced Level】1015. Reversible Primes (20)
- zookeeper 数据节点的增删改查
- 虚拟机VMware12.0安装centos 6.5+VMware中虚拟机网络模式区分
- module_param 用于动态开启/关闭 驱动打印信息
热门文章
- erlang防止反编译
- 2016/07/07 wamp中apache2.4.9允许外部访问的配置 重点是版本 版本不同配置效果不同
- 51 NOD 1753 相似子串 字符串hash
- linux修改进程的名字
- yum 工作原理
- Mixtures of Gaussians and the EM algorithm
- Recurrent neural networks are very powerful, because they combine two properties
- PAT 天梯赛 L1-049. 天梯赛座位分配 【循环】
- python 实用pickle序列化
- Emscripten实现把C/C++文件转成wasm,wast(wasm的可读形式),llvm字节码(bc格式),ll格式(llvm字节码的可读形式)并执行wasm