QOJ.ac

QOJ

時間限制: 2.0 s 記憶體限制: 1024 MB 總分: 100 可 Hack ✓

#17869. 直方图序列

统计

直方图是由 $N$ 个共享同一条基准线的相邻矩形排列而成的多边形。每个矩形被称为一个条形(bar)。从左往右数第 $i$ 个条形的宽度为 1,高度为 $H_i$。

图:该图描绘了 $N = 9$ 且 $H = [7, 4, 3, 5, 4, 2, 5, 1, 2]$ 的情况。

一天,你想要求出给定直方图中所包含的最大矩形的面积。你通过以下步骤创建了一个整数列表 $A$:

  • 对于每个 $1 \le i \le j \le N$,计算包含在直方图中的最大矩形面积,其中该矩形的底边与第 $i, i + 1, \dots, j - 1, j$ 个条形的底边重合。将该面积加入列表 $A$ 中。

图:该图描绘了 $i = 3$ 且 $j = 5$ 的情况。面积为 9。

由于你恰好选择了每个数对 $(i, j)$ 一次,列表 $A$ 的长度恰好为 $\frac{N(N+1)}{2}$。为了方便起见,你将列表 $A$ 按非递减顺序进行了排序。现在,要找到直方图中所包含的最大矩形面积,你只需要读取 $A$ 的最后一个元素 $A_{N(N+1)/2}$。

然而,你对此并不满足,因此我决定让你计算列表 $A$ 的某一部分。你需要编写一个程序,在给定两个索引 $L$ 和 $R$ ($L \le R$) 的情况下,计算 $A_{L..R}$ 的值,即 $A_L, A_{L+1}, \dots, A_{R-1}, A_R$。

输入格式

第一行包含一个整数 $N$ ($1 \le N \le 300\,000$),表示直方图中条形的数量。

第二行包含 $N$ 个空格分隔的正整数 $H_1, H_2, \dots, H_N$ ($1 \le H_i \le 10^9$),其中 $H_i$ 是第 $i$ 个条形的高度。

最后一行包含两个整数 $L$ 和 $R$ ($1 \le L \le R \le \frac{N(N+1)}{2}$,$R - L + 1 \le 300\,000$)。

输出格式

输出 $R - L + 1$ 个整数。其中第 $j$ 个($1 \le j \le R - L + 1$)整数应当是列表 $A$ 的第 $L + j - 1$ 个元素,即 $A_{L+j-1}$。

样例

样例输入 1

9
7 4 3 5 4 2 5 1 2
42 45

样例输出 1

12 12 14 15

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.