QOJ.ac

QOJ

時間限制: 3 s 記憶體限制: 512 MB 總分: 25 难度: [顯示]

#18496. Melborp

统计

Seta 正在为 CCO 出题!她想出了以下问题:

给定一个数组 $A[1, \dots, N]$,其值在范围 $[1, N]$ 内,定义 $B[i]$ 为满足 $\ell \le i \le r$ 且 $$A[i] = \min(A[\ell], A[\ell+1], \dots, A[r-1], A[r])$$ 的数对 $(\ell, r)$ 的数量。

请输出数组 $B[1, \dots, N]$。

然而,在 CCO 开始的前一天,Seta 的电脑崩溃了,她只找回了输出文件。给定输出数组 $B[1, \dots, N]$,你能编写一个程序来重构输入数组 $A[1, \dots, N]$ 吗?

Seta 提醒你,数组 $A$ 不一定是唯一的,她会接受任何合法的数组。

输入格式

第一行包含一个整数 $N$。第二行包含 $N$ 个空格分隔的整数 $B[1], \dots, B[N]$ ($1 \le B[i] \le N^2$)。

下表显示了 25 分的分布情况:

分值 $N$ 的范围 附加约束
2 分 $1 \le N \le 8$
3 分 $1 \le N \le 5\,000$ 原数组 $A$ 是一个排列
5 分 $1 \le N \le 3 \times 10^5$ 原数组 $A$ 是一个排列
5 分 $1 \le N \le 3 \times 10^5$
5 分 $1 \le N \le 5 \times 10^6$ 原数组 $A$ 是一个排列
5 分 $1 \le N \le 5 \times 10^6$

输出格式

输出 $N$ 个空格分隔的整数,即数组 $A[1], \dots, A[N]$,其中 $1 \le A[i] \le N$。保证至少存在一个合法的数组 $A$。

如果存在多个合法的数组,你可以输出其中任意一个。特别地,即使原数组 $A$ 是一个排列,你的答案也不必是一个排列。

样例

样例输入 1

3
3 1 2

样例输出 1

1 3 2

说明 1

  • 子数组 $[1, 3, 2], [1, 3], [1]$ 的最小值为 $1$。共有 $3$ 个这样的子数组。
  • 子数组 $[3]$ 的最小值为 $3$。共有 $1$ 个这样的子数组。
  • 子数组 $[3, 2]$ 和 $[2]$ 的最小值为 $2$。共有 $2$ 个这样的子数组。

样例输入 2

2
2 2

样例输出 2

1 1

样例输入 3

3
1 4 1

样例输出 3

2 1 3

说明 3

注意 $A = [2, 1, 2]$ 也会被评测系统接受。

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.