QOJ.ac

QOJ

Time Limit: 3 s Memory Limit: 512 MB Total points: 25 Difficulty: [show]

#18496. Melborp

Statistics

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 5000$ 原始陣列 $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, 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

說明

注意 $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.