秋实大哥去打工

Time Limit: 1 Sec  Memory Limit: 256 MB

题目连接

http://acm.uestc.edu.cn/#/contest/show/59

Description

天行健,君子以自强不息。地势坤,君子以厚德载物。

天天过节的秋实大哥又要过节了,于是他要给心爱的妹子买礼物。但由于最近秋实大哥手头拮据,身为一个男人,他决定去打工!

秋实大哥来到一家广告公司。现在有n块矩形墙从左至右紧密排列,每一块高为Hi,宽为Wi。

公司要求秋实大哥找出一块最大的连续矩形区域,使得公司可以在上面贴出最大的海报。

Input

第一行包含一个整数n,表示矩形墙的个数。

接下来n行,每行有两个整数Wi,Hi,表示第i块墙的宽度和高度。

1≤n≤200000,保证Wi,Hi以及最后的答案<231。

Output

最大的连续矩形的面积。

Sample Input

3
3 4
1 2
3 4

Sample Output

14

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题 秋实大哥去打工 单调栈的更多相关文章

  1. 2015 UESTC 数据结构专题N题 秋实大哥搞算数 表达式求值/栈

    秋实大哥搞算数 Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/problem/show/1074 Des ...

  2. 2015 UESTC 数据结构专题B题 秋实大哥与花 线段树 区间加,区间查询和

    B - 秋实大哥与花 Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/contest/show/59 De ...

  3. 2015 UESTC 数据结构专题H题 秋实大哥打游戏 带权并查集

    秋实大哥打游戏 Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/contest/show/59 Descr ...

  4. 2015 UESTC 数据结构专题E题 秋实大哥与家 线段树扫描线求矩形面积交

    E - 秋实大哥与家 Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/contest/show/59 De ...

  5. 2015 UESTC 数据结构专题D题 秋实大哥与战争 SET的妙用

    D - 秋实大哥与战争 Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/contest/show/59 D ...

  6. 2015 UESTC 数据结构专题D题 秋实大哥与战争 变化版本的线段树,合并区间,单点查询

    D - 秋实大哥与战争 Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/contest/show/59 D ...

  7. 2015 UESTC 数据结构专题C题 秋实大哥与快餐店 字典树

    C - 秋实大哥与快餐店 Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/contest/show/59 ...

  8. 2015 UESTC 数据结构专题A题 秋实大哥与小朋友 线段树 区间更新,单点查询,离散化

    秋实大哥与小朋友 Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/contest/show/59 Desc ...

  9. CDOJ 1069 秋实大哥去打工 单调栈 下标处理

    E - 秋实大哥去打工 Time Limit:1000MS     Memory Limit:65535KB     64bit IO Format:%lld & %llu Submit St ...

随机推荐

  1. 013 GC机制

    本文转自:https://www.cnblogs.com/shudonghe/p/3457990.html 最近还是在找工作,在面试某移动互联网公司之前认为自己对Java的GC机制已经相当了解,其他面 ...

  2. 斐讯路由器L(联)B(壁)K-码兑换包安全下车通道(图文教程)

    大家好,最近大家比较关心的斐讯路由器如何下车问题,楼主亲自试提取了一遍,记录下过程,欢迎大家一起讨论. 言归正传,上图,上图! No.1 打开斐讯提供的良心k码退换通道: https://tech-s ...

  3. spring-mybatis.xml配置

    1.自动扫描 <context:component-scan base-package="com.javen" /> 2.引入配置文件 <bean id=&quo ...

  4. [ python ] 练习作业 - 3

    1. 写出Python查找一个变量的顺序 提示:4中作用域的顺序 本地作用域(local) --> 当前作用域被嵌入的本地作用域(enclsing locals) --> 全局/模块作用域 ...

  5. Linux软件管理器(如何使用软件管理器来管理软件)

    我们的Linux系统大部分都是某个Linux厂商的系统,所以这些厂商可以编译好一些软件来提供用户下载,用户下载完了之后就可以直接安装,从而省去了编译源码及其过程中的各种问题.这时我们就可以使用相应的软 ...

  6. CentOS下NTP安装配置

      安装yum install ntp 配置文件 /etc/ntp.confrestrict default kod nomodifynotrap nopeer noqueryrestrict -6 ...

  7. npm install 装本地一直安装全局问题

    想用npm安装一些模块,不管怎么装,一直装作全局. 以为是node有问题,重装了N次,却还发现这个问题. 困惑几天无果, 偶然间通过此文章发现,npm存在配置文件:https://www.sitepo ...

  8. Django 注册

    一. 本地图片上传预览 1. 上传文件框隐藏到图片上面,点击图片相当于点上传文件框 <div class="login"> <div style="po ...

  9. 不需要打密码的sudo方法

    Linux下频繁输入sudo很麻烦.如果你的账户已经是sudoer了,那么编辑/etc/sudoers,将 %sudo ALL=(ALL:ALL) ALL 修改为: %sudo ALL=(ALL) N ...

  10. ros nodelet 使用

    ros nodelet能够加快高吞吐量程序运行速度比如点云 基本入门程序可以看 http://wiki.ros.org/nodelet/Tutorials/Porting%20nodes%20to%2 ...