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 ...
 
随机推荐
- linux常用命令一些解释
			
ls 命令是linux下最常用的命令.ls命令就是list的缩写缺省下ls用来打印出当前目录的清单如果ls指定其他目录那么就会显示指定目录里的文 件及文件夹清单. 通过ls 命令不仅可以查看li ...
 - 64_s3
			
sugar-toolkit-gtk3-devel-0.110.0-2.fc26.i686.rpm 13-Feb-2017 10:56 22626 sugar-toolkit-gtk3-devel-0. ...
 - juery下拉刷新,div加载更多元素并添加点击事件(二)
			
buffer.append("<div class='col-xs-3 "+companyId+"' style='padding-left: 10px; padd ...
 - 使用angluar-cli的ng g component home指令出现的错误
			
Error: ELOOP: too many symbolic links encountered, stat '/Users/zzy/angular/taskmgr/node_modules/@an ...
 - C/C++——二维数组与指针、指针数组、数组指针(行指针)、二级指针的用法
			
本文转载自:https://blog.csdn.net/qq_33573235/article/details/79530792 1. 二维数组和指针 要用指针处理二维数组,首先要解决从存储的角度对二 ...
 - Transport failed: java.io.EOFException
			
ActiveMQ服务端有时会报Transport failed: java.io.EOFException这样的错误,这是由客户端丢失连接并反复尝试连接导致的,不是什么大问题,有时网络波动就会产生这种 ...
 - 四、ansible主机组定义
			
1.打开hosts文件 vim /etc/ansible/hosts 2.定义一个主机组 [web-server] 192.168.1.1 3.定义多个组(继承) [web:children] web ...
 - poj 2420(模拟退火)
			
A Star not a Tree? Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6066 Accepted: 285 ...
 - 洛谷 P2241统计方形(数据加强版) 题解
			
题目传送门 说是加强版,其实可以把棋盘那道题的代码粘过来(注意要开long long): #include<bits/stdc++.h> using namespace std; ,c; ...
 - MINIBASE源代码阅读笔记之DB
			
DB 管理数据库的类 file_entry:dir page的元素,保存不同文件对应的page directory_page:dir page的专用结构体,里面有个初始长度为0的variable si ...