#P16902. [CCO 2026] Melborp

    ID: 19243 远端评测题 3000ms 512MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>Special Judge分治CCO(加拿大)2026笛卡尔树单调栈

[CCO 2026] Melborp

Problem Description

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 ir\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.

Input Format

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] (1B[i]N21 \le B[i] \le N^2).

Output Format

Output NN space-separated integers, the array A[1],,A[N]A[1],\ldots,A[N], where 1A[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

Hint

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 1N81 \le N \le 8 None.
33 marks 1N50001 \le N \le 5\,000 The original array AA is a permutation.
55 marks 1N3×1051 \le N \le 3 \times 10^5
^ None.
1N5×1061 \le N \le 5 \times 10^6 The original array AA is a permutation.
^ None.