AT_arc227_b.Know Your Place
普及+/提高
通过率:0%
时间限制:2.00s
内存限制:1024MB
AC君温馨提醒
该题目为【atcoder】题库的题目,您提交的代码将被提交至atcoder进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given a length-N sequence of non-negative integers A=(A1,A2,…,AN).
Determine whether there exists a sequence B=(B1,B2,…,BN) that is a permutation of A that satisfies the following condition for every i=1,2,…,N, and construct one such sequence if it exists.
- Bi is equal to the number of integers j satisfying 1≤j<i and Bj<Bi.
给你一个长度为 N 的非负整数序列 A=(A1,A2,…,AN)。
判断是否存在一个序列 B=(B1,B2,…,BN),使得 B 是 A 的一个排列,并且对每个 i=1,2,…,N 均满足以下条件;若存在,构造出这样一个序列 B。
- Bi 等于满足 1≤j<i 且 Bj<Bi 的整数 j 的个数。
输入格式
The input is given from Standard Input in the following format:
N
A1 A2 … AN
输入从标准输入中按以下格式给出:
N
A1 A2 … AN
输出格式
If there is no sequence B satisfying the condition, output No.
If one exists, output Yes and a sequence B in the following format:
Yes
B1 B2 … BN
If multiple sequences satisfy the condition, you may output any of them.
如果不存在满足条件的序列 B,则输出 No。
如果存在,则输出 Yes 以及一个满足条件的序列 B,格式如下:
Yes
B1 B2 … BN
若存在多个满足条件的序列,输出其中任意一个即可。
输入输出样例
输入#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 A. For i=1,2,3,4, the number of elements to the left of Bi that are smaller than Bi is 0,1,0,3, respectively, which equals Bi.
Sample 2 Explanation:
Since there is only one element smaller than the value 2, no permutation satisfies the condition.
Sample 3 Explanation:
The output sequence is a permutation of A. For i=1,2,…,7, the number of elements to the left of Bi that are smaller than Bi is 0,1,1,3,4,4,6, respectively, which equals Bi.
Constraints
- 1≤N≤5×105
- 0≤Ai<N
- All input values are integers.
样例 1 解释:
输出序列 B 是 A 的一个排列。对于 i=1,2,3,4,位于 Bi 左侧且小于 Bi 的元素个数分别为 0,1,0,3,恰好等于 Bi。
样例 2 解释:
由于小于数值 2 的元素仅有一个,因此不存在满足条件的排列。
样例 3 解释:
输出序列 B 是 A 的一个排列。对于 i=1,2,…,7,位于 Bi 左侧且小于 Bi 的元素个数分别为 0,1,1,3,4,4,6,恰好等于 Bi。
限制条件
- 1≤N≤5×105
- 0≤Ai<N
- 所有输入值均为整数。
输入解题思路,AI测评打分。不知道怎么写?