#P16902. [CCO 2026] Melborp

    ID: 17162 Type: RemoteJudge 3000ms 512MiB Tried: 0 Accepted: 0 Difficulty: 8 Uploaded By: Tags>Special Judge分治CCO(加拿大)2026笛卡尔树单调栈

[CCO 2026] Melborp

题目描述

Seta is creating problems for the CCO! She came up with the following problem:

Given an array A[1,…,N]A[1,\ldots,N] whose values are in the range [1,N][1,N], define B[i]B[i] to be the number of pairs (ℓ,r)(\ell,r) such that ℓ≤i≤r\ell \le i \le r and $A[i] = \min(A[\ell], A[\ell + 1], \ldots, A[r - 1], A[r])$.

Print the array B[1,…,N]B[1,\ldots,N].

However, the day before the CCO, Seta’s computer crashed, and she was only able to recover the output files. Given the output array B[1,…,N]B[1,\ldots,N], can you write a program to reconstruct the input array A[1,…,N]A[1,\ldots,N]?

Seta reminds you that the array AA is not necessarily unique, and she will accept any valid array.

输入格式

The first line of input will contain a single integer, NN. The second line of input will contain NN space-separated integers B[1],…,B[N]B[1],\ldots,B[N] (1≤B[i]≤N21 \le B[i] \le N^2).

输出格式

Output NN space-separated integers, the array A[1],…,A[N]A[1],\ldots,A[N], where 1≤A[i]≤N1 \le A[i] \le N. It is guaranteed that there will always exist at least one valid array AA.

If there is more than one valid array, you may output any valid array. In particular, even if the original array AA is a permutation, your answer does not have to be a permutation.

3
3 1 2
1 3 2
2
2 2
1 1
3
1 4 1
2 1 3

提示

Explanation of Output for Sample Input 11

  • The subarrays [1,3,2][1,3,2], [1,3][1,3], [1][1] have minimum 11. There are 33 such subarrays.
  • The subarray [3][3] has minimum 33. There is 11 such subarray.
  • The subarrays [3,2][3,2] and [2][2] have minimum 22. There are 22 such subarrays.

Explanation of Output for Sample Input 33

Note that A=[2,1,2]A = [2,1,2] would also be accepted by the judge.

The following table shows how the 2525 available marks are distributed:

Marks Awarded Bounds on NN Additional Constraints
22 marks 1≤N≤81 \le N \le 8 None.
33 marks 1≤N≤5 0001 \le N \le 5\,000 The original array AA is a permutation.
55 marks 1≤N≤3×1051 \le N \le 3 \times 10^5
^ None.
1≤N≤5×1061 \le N \le 5 \times 10^6 The original array AA is a permutation.
^ None.