2015 UESTC 数据结构专题G题 秋实大哥去打工 单调栈
秋实大哥去打工
Time Limit: 1 Sec Memory Limit: 256 MB
题目连接
http://acm.uestc.edu.cn/#/contest/show/59
Description
天行健,君子以自强不息。地势坤,君子以厚德载物。
天天过节的秋实大哥又要过节了,于是他要给心爱的妹子买礼物。但由于最近秋实大哥手头拮据,身为一个男人,他决定去打工!
秋实大哥来到一家广告公司。现在有n块矩形墙从左至右紧密排列,每一块高为Hi,宽为Wi。
公司要求秋实大哥找出一块最大的连续矩形区域,使得公司可以在上面贴出最大的海报。
Input
接下来n行,每行有两个整数Wi,Hi,表示第i块墙的宽度和高度。
1≤n≤200000,保证Wi,Hi以及最后的答案<231。
Output
Sample Input
3 4
1 2
3 4
Sample Output
HINT
题意
题解:
初看这道题,啊好难啊
代码:
//qscqesze
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 200001
#define mod 10007
#define eps 1e-9
//const int inf=0x7fffffff; //无限大
const int inf=0x3f3f3f3f;
/*
inline ll read()
{
int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
int buf[10];
inline void write(int i) {
int p = 0;if(i == 0) p++;
else while(i) {buf[p++] = i % 10;i /= 10;}
for(int j = p-1; j >=0; j--) putchar('0' + buf[j]);
printf("\n");
}
*/
//**************************************************************************************
using namespace std;
long long a[maxn],b[maxn],ans;
int r[maxn],l[maxn];
stack<int> s;
int main()
{
int n;
scanf("%d",&n);
a[]=a[n+]=-;
for(int i=;i<=n;i++)
{
scanf("%d",&b[i]);
b[i]+=b[i-];
scanf("%lld",&a[i]);
}
s.push();
int p=;
for(int i=;i<=n;i++)
{
for(p=s.top();a[p]>=a[i];p=s.top())
s.pop();
l[i]=p+;
s.push(i);
}
while(!s.empty())
s.pop();
s.push(n+);
for(int i=n;i>;i--)
{
for(p=s.top();a[p]>=a[i];p=s.top())
s.pop();
r[i]=p-;
s.push(i);
}
for(int i=;i<=n;i++)
ans=max(ans,((b[r[i]]-b[i-])+(b[i-]-b[l[i]-]))*a[i]);
printf("%lld\n",ans);
return ;
}
2015 UESTC 数据结构专题G题 秋实大哥去打工 单调栈的更多相关文章
- 2015 UESTC 数据结构专题N题 秋实大哥搞算数 表达式求值/栈
秋实大哥搞算数 Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/problem/show/1074 Des ...
- 2015 UESTC 数据结构专题B题 秋实大哥与花 线段树 区间加,区间查询和
B - 秋实大哥与花 Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/contest/show/59 De ...
- 2015 UESTC 数据结构专题H题 秋实大哥打游戏 带权并查集
秋实大哥打游戏 Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/contest/show/59 Descr ...
- 2015 UESTC 数据结构专题E题 秋实大哥与家 线段树扫描线求矩形面积交
E - 秋实大哥与家 Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/contest/show/59 De ...
- 2015 UESTC 数据结构专题D题 秋实大哥与战争 SET的妙用
D - 秋实大哥与战争 Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/contest/show/59 D ...
- 2015 UESTC 数据结构专题D题 秋实大哥与战争 变化版本的线段树,合并区间,单点查询
D - 秋实大哥与战争 Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/contest/show/59 D ...
- 2015 UESTC 数据结构专题C题 秋实大哥与快餐店 字典树
C - 秋实大哥与快餐店 Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/contest/show/59 ...
- 2015 UESTC 数据结构专题A题 秋实大哥与小朋友 线段树 区间更新,单点查询,离散化
秋实大哥与小朋友 Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/contest/show/59 Desc ...
- CDOJ 1069 秋实大哥去打工 单调栈 下标处理
E - 秋实大哥去打工 Time Limit:1000MS Memory Limit:65535KB 64bit IO Format:%lld & %llu Submit St ...
随机推荐
- Cesium 初始化Viewer
<pre name="code" class="javascript"><script> var viewer = new Cesium ...
- 【Python学习】使用BeautifulSoup解析HTML
对于一个最简单的爬虫结构的代码是这样的. 也就是抓取出整个页面,然后创建一个BeautifulSoup对象. from urllib.request import urlopen from bs4 i ...
- 记一个多线程使用libevent的问题
前段时间使用libevent网络库实现了一个游戏服务器引擎,在此记录下其中遇到的一个问题. 我在设计服务器上选择把逻辑和网络分线程,线程之间通信使用队列.但是这样做会有个问题: 当逻辑线程想要主动的发 ...
- C# 开发(创蓝253)手机短信验证码接口
创蓝253: https://www.253.com/ #region 获取手机验证码(创蓝253) /// <summary> /// 获取手机验证码(创蓝253) /// </s ...
- LINUX内核中的机制OOM
[概念] LINUX内核中有一个机制叫做OOM killer(Out Of Memery killer) 该机制监控内存占用过大,尤其是瞬间消耗大量内存的进程, 为了防止内存被耗尽,所以OOM kil ...
- 用js实现图片连播和联级菜单的实现
<!DOCTYPE html> <html> <head> <title>图片轮播</title> <style> div{ b ...
- ASP.NET Core 2.0 MVC 发布部署--------- IIS 具体操作
.Net Core 部署到 IIS系统中的步骤 一.IIS 配置 启用 Web 服务器 (IIS) 角色并建立角色服务. 1.Windows Ddesktop 桌面操作系统(win7及更高版本) 导航 ...
- Jmeter组件和属性(二)
Jmeter脚本开发原则 简单.正确.高效.简单:去除无关的组件,同时能复用的尽量复用.正确:对脚本或者业务正确性进行必要的判断,不能少也不能多.(200),业务错误的情况下,也可能返回200,必须用 ...
- 开始学习MaxCompute
https://help.aliyun.com/document_detail/34615.html?spm=a2c4g.11186623.6.688.jVxTMW
- 【转】Serializers 序列化组件
https://www.cnblogs.com/MayDayTime/p/9890582.html 为什么要用序列化组件 当我们做前后端分离的项目~~我们前后端交互一般都选择JSON数据格式,JSON ...