AT_arc227_b.Know Your Place

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:1024MB

AC君温馨提醒

该题目为【atcoder】题库的题目,您提交的代码将被提交至atcoder进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given a length-NN sequence of non-negative integers A=(A1,A2,…,AN)A=(A_1,A_2,\ldots,A_N).

Determine whether there exists a sequence B=(B1,B2,…,BN)B=(B_1,B_2,\ldots,B_N) that is a permutation of AA that satisfies the following condition for every i=1,2,…,Ni=1,2,\ldots,N, and construct one such sequence if it exists.

  • BiB_i is equal to the number of integers jj satisfying 1≤j<i1 \le j < i and Bj<BiB_j < B_i.

给你一个长度为 NN 的非负整数序列 A=(A1,A2,…,AN)A=(A_1,A_2,\ldots,A_N)。

判断是否存在一个序列 B=(B1,B2,…,BN)B=(B_1,B_2,\ldots,B_N),使得 BB 是 AA 的一个排列,并且对每个 i=1,2,…,Ni=1,2,\ldots,N 均满足以下条件;若存在,构造出这样一个序列 BB。

  • BiB_i 等于满足 1≤j<i1 \le j < i 且 Bj<BiB_j < B_i 的整数 jj 的个数。

输入格式

The input is given from Standard Input in the following format:

NN
A1A_1 A2A_2 …\ldots ANA_N

输入从标准输入中按以下格式给出:

NN
A1A_1 A2A_2 …\ldots ANA_N

输出格式

If there is no sequence BB satisfying the condition, output No.

If one exists, output Yes and a sequence BB in the following format:

Yes
B1B_1 B2B_2 …\ldots BNB_N

If multiple sequences satisfy the condition, you may output any of them.

如果不存在满足条件的序列 BB,则输出 No。

如果存在,则输出 Yes 以及一个满足条件的序列 BB,格式如下:

Yes
B1B_1 B2B_2 …\ldots BNB_N

若存在多个满足条件的序列,输出其中任意一个即可。

输入输出样例

  • 输入#1

    4
    3 0 1 0

    输出#1

    Yes
    0 1 0 3
  • 输入#2

    3
    0 2 2

    输出#2

    No
  • 输入#3

    7
    4 1 6 0 4 3 1

    输出#3

    Yes
    0 1 1 3 4 4 6

说明/提示

Sample 1 Explanation:
The output sequence is a permutation of AA. For i=1,2,3,4i=1,2,3,4, the number of elements to the left of BiB_i that are smaller than BiB_i is 0,1,0,30,1,0,3, respectively, which equals BiB_i.

Sample 2 Explanation:
Since there is only one element smaller than the value 22, no permutation satisfies the condition.

Sample 3 Explanation:
The output sequence is a permutation of AA. For i=1,2,…,7i=1,2,\ldots,7, the number of elements to the left of BiB_i that are smaller than BiB_i is 0,1,1,3,4,4,60,1,1,3,4,4,6, respectively, which equals BiB_i.

Constraints

  • 1≤N≤5×1051 \le N \le 5 \times 10^5
  • 0≤Ai<N0 \le A_i < N
  • All input values are integers.

样例 1 解释:
输出序列 BB 是 AA 的一个排列。对于 i=1,2,3,4i=1,2,3,4,位于 BiB_i 左侧且小于 BiB_i 的元素个数分别为 0,1,0,30,1,0,3,恰好等于 BiB_i。

样例 2 解释:
由于小于数值 22 的元素仅有一个,因此不存在满足条件的排列。

样例 3 解释:
输出序列 BB 是 AA 的一个排列。对于 i=1,2,…,7i=1,2,\ldots,7,位于 BiB_i 左侧且小于 BiB_i 的元素个数分别为 0,1,1,3,4,4,60,1,1,3,4,4,6,恰好等于 BiB_i。

限制条件

  • 1≤N≤5×1051 \le N \le 5 \times 10^5
  • 0≤Ai<N0 \le A_i < N
  • 所有输入值均为整数。

输入解题思路,AI测评打分。不知道怎么写?

首页