Die datenstruktur ist erataunlich!

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#define R(a,b,c) for(register int a = (b); a <= (c); ++ a)
#define nR(a,b,c) for(register int a = (b); a >= (c); -- a)
#define Max(a,b) ((a) > (b) ? (a) : (b))
#define Min(a,b) ((a) < (b) ? (a) : (b))
#define Fill(a,b) memset(a, b, sizeof(a))
#define Swap(a,b) a^=b^=a^=b
#define ll long long
#define ON_DEBUG #ifdef ON_DEBUG #define D_e_Line printf("\n\n----------\n\n")
#define D_e(x) cout << #x << " = " << x << endl
#define Pause() system("pause") #else #define D_e_Line ; #endif struct ios{
template<typename ATP>ios& operator >> (ATP &x){
x = 0; int f = 1; char c;
for(c = getchar(); c < '0' || c > '9'; c = getchar()) if(c == '-') f = -1;
while(c >= '0' && c <= '9') x = x * 10 + (c ^ '0'), c = getchar();
x*= f;
return *this;
}
}io;
using namespace std; const int N = 100007; int n; struct node{
int val, pri, fa, l, r; bool operator < (const node &com)const{
return val < com.val;
}
}t[N]; int root;
long long ans; inline int Build(){
R(i,1,n){
int k;
for(k = i - 1; t[k].pri > t[i].pri; k = t[k].fa);
t[i].l = t[k].r;
t[k].r = i;
t[i].fa = k;
t[t[i].l].fa = i;
}
return t[0].r;
} inline long long DFS(int x){
if(!x) return 0;
long long width = DFS(t[x].l) + DFS(t[x].r) + 1;
long long tmp = t[x].pri * width;
ans = Max(ans, tmp);
return width;
}
int main(){
while(scanf("%d", &n) && n){
t[0].l = t[0].r = t[0].fa = t[0].pri = t[0].val = 0;
R(i,1,n){
t[i].val = i;
io >> t[i].pri;
t[i].l = t[i].r = t[i].fa = 0;
} root = Build(); ans = 0; DFS(root); printf("%lld\n", ans);
}
return 0;
}

POJ2559/HDU1506 Largest Rectangle in a Histogram (cartesian tree)的更多相关文章

  1. NYOJ-258/POJ-2559/HDU-1506 Largest Rectangle in a Histogram,最大长方形,dp或者单调队列!

                                         Largest Rectangle in a Histogram 这么经典的题硬是等今天碰到了原题现场懵逼两小时才会去补题.. ...

  2. [POJ2559&POJ3494] Largest Rectangle in a Histogram&Largest Submatrix of All 1’s 「单调栈」

    Largest Rectangle in a Histogram http://poj.org/problem?id=2559 题意:给出若干宽度相同的矩形的高度(条形统计图),求最大子矩形面积 解题 ...

  3. hdu---1506(Largest Rectangle in a Histogram/dp最大子矩阵)

    Largest Rectangle in a Histogram Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 ...

  4. hdu1506——Largest Rectangle in a Histogram

    Largest Rectangle in a Histogram Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 ...

  5. hdu1506 Largest Rectangle in a Histogram

    Problem Description A histogram is a polygon composed of a sequence of rectangles aligned at a commo ...

  6. HDU1506 Largest Rectangle in a Histogram (动规)

    Largest Rectangle in a Histogram Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 ...

  7. 【题解】hdu1506 Largest Rectangle in a Histogram

    目录 题目 思路 \(Code\) 题目 Largest Rectangle in a Histogram 思路 单调栈. 不知道怎么描述所以用样例讲一下. 7 2 1 4 5 1 3 3 最大矩形的 ...

  8. HDU-1506 Largest Rectangle in a Histogram【单调栈】

    Description A histogram is a polygon composed of a sequence of rectangles aligned at a common base l ...

  9. [dp]POJ2559 && HDOJ1506 Largest Rectangle in a Histogram

    题意 给n个条形的高度, 问能放的最大矩形面积 分析: 从左到右 从右到左 各搞一遍 分别记录      L[i]记录列(从前往后)标 第几列开始 可以往后放高度为a[i]的矩形  R[i]记录列(从 ...

随机推荐

  1. Property or method "xxx" is not defined on the instance but referenced during render

    是xxx中的data写成date了,因此报错. 这个错误属于粗心

  2. Spring-Cloud-Alibaba系列教程(一)Nacos初识

    前言 在2020年即将开启SpringCloudAlibaba的专题,希望2020年共同学习进步. 学习资料 文档 Naco文档 程序猿DD Spring Cloud Aliabab专题 专题博客 视 ...

  3. 区分 python 爬虫或者是写自动化脚本时遇到的 content与text的作用

    通常在使用过程中或许我们能够轻而易举的会使用requsts模块中的content 与 text ,从print结果来看根本看不出任何区别: 总结精髓,text 返回的是unicode 型的数据,一般是 ...

  4. CabloyJS自带工作流引擎的文档清单

    文档清单 CabloyJS自带工作流引擎文档已经整理出来,欢迎大家围观.拍砖 介绍 介绍 演示:CMS审批工作流 单元测试用例集 流程定义 基本概念 JSON规范 listener规范 listene ...

  5. 部署ASP.NET Core最简单的办法,使用IIS部署ASP.NET Core应用

    本文迁移自Panda666原博客,原发布时间:2021年3月28日.写原文的时候.NET的最新版本是5.0,现在7的preview出来了,时间真快啊.抽空再写个在Windows Server Core ...

  6. pytorch自定义模型时实现父类构造函数的问题

    问题 有的类继承nn.Module在init函数里面是super(类名, self).init():但是有的里面就是super().init() exp: · 解答: python2与python3的 ...

  7. Nginx通过bat文件快速启动停止

    新建文本文件NginxRun.bat.(名字无所谓,后缀名得是bat) 将以下代码复制到bat文件中即可. @echo off ::进入D盘 d: ::进入nginx目录 这里是自己的nginx目录 ...

  8. Spring XmlBeanFactory 容器的基本实现

    容器的基本用法 熟悉 Spring 的朋友应该都很了解下段代码: public void testBeanFactory() { BeanFactory bf = new XmlBeanFactory ...

  9. Eclipse拷贝动态的web工程

    1.选中需要拷贝的工程,CTRL+C,然后CTRL+V 2.在web动态工程中,还需要选中新拷贝工程,右键选中properties,然后搜索web,--->Web Project Setttin ...

  10. 准备java编程软件与第一个java程序

    我们要用的java的编程软件叫做:eclipse windows上安装eclipse 首先需要一个浏览器 要下载eclipse最简单的方式就是在官网下载  官网:https://www.eclipse ...