CF1252A.Copying Homework

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Danang and Darto are classmates. They are given homework to create a permutation of NN integers from 11 to NN. Danang has completed the homework and created a permutation AA of NN integers. Darto wants to copy Danang's homework, but Danang asks Darto to change it up a bit so it does not look obvious that Darto copied.

The difference of two permutations of NN integers AA and BB, denoted by diff(A,B)diff(A, B), is the sum of the absolute difference of AiA_i and BiB_i for all ii. In other words, diff(A,B)=Σi=1N∣Ai−Bi∣diff(A, B) = \Sigma_{i=1}^N |A_i - B_i|. Darto would like to create a permutation of NN integers that maximizes its difference with AA. Formally, he wants to find a permutation of NN integers BmaxB_{max} such that diff(A,Bmax)≥diff(A,B′)diff(A, B_{max}) \ge diff(A, B') for all permutation of NN integers B′B'.

Darto needs your help! Since the teacher giving the homework is lenient, any permutation of NN integers BB is considered different with AA if the difference of AA and BB is at least NN. Therefore, you are allowed to return any permutation of NN integers BB such that diff(A,B)≥Ndiff(A, B) \ge N.

Of course, you can still return BmaxB_{max} if you want, since it can be proven that diff(A,Bmax)≥Ndiff(A, B_{max}) \ge N for any permutation AA and N>1N \gt 1. This also proves that there exists a solution for any permutation of NN integers AA. If there is more than one valid solution, you can output any of them.

丹ang 和 Darto 是同班同学。老师布置了作业,要求他们各自构造一个由 11 到 NN 的 NN 个整数组成的排列。丹ang 已经完成了作业,并构造了一个排列 AA。Darto 想抄丹ang 的作业,但丹ang 要求 Darto 稍作修改,以免明显看出是抄袭。

两个 NN 整数排列 AA 和 BB 的差异(记为 diff(A,B)diff(A, B))定义为:对所有 ii,AiA_i 与 BiB_i 的绝对差之和。即

diff(A,B)=∑i=1N∣Ai−Bi∣.diff(A, B) = \sum_{i=1}^N |A_i - B_i|.

Darto 希望构造一个 NN 整数排列 BB,使其与 AA 的差异尽可能大。形式化地说,他希望找到一个 NN 整数排列 BmaxB_{max},使得对任意 NN 整数排列 B′B',均有

diff(A,Bmax)≥diff(A,B′).diff(A, B_{max}) \ge diff(A, B').

Darto 需要你的帮助!由于布置该作业的老师比较宽容,只要排列 BB 与 AA 的差异至少为 NN,就认为 BB 与 AA 不同。因此,你只需返回任意一个 NN 整数排列 BB,满足

diff(A,B)≥N.diff(A, B) \ge N.

当然,你仍然可以选择输出 BmaxB_{max}(即使差异最大化的排列),因为可以证明:对任意排列 AA 及任意 N>1N > 1,均有 diff(A,Bmax)≥Ndiff(A, B_{max}) \ge N。这也说明:对任意 NN 整数排列 AA,解一定存在。若存在多个合法解,输出其中任意一个即可。

输入格式

Input begins with a line containing an integer: NN (2≤N≤100 0002 \le N \le 100\,000) representing the size of Danang's permutation. The next line contains NN integers: AiA_i (1≤Ai≤N1 \le A_i \le N) representing Danang's permutation. It is guaranteed that all elements in AA are distinct.

输入的第一行包含一个整数:NN(2≤N≤100 0002 \le N \le 100\,000),表示丹昂排列的长度。
接下来的一行包含 NN 个整数:AiA_i(1≤Ai≤N1 \le A_i \le N),表示丹昂的排列。
保证数组 AA 中的所有元素互不相同。

输出格式

Output in a line NN integers (each separated by a single space) representing the permutation of NN integers BB such that diff(A,B)≥Ndiff(A, B) \ge N. As a reminder, all elements in the permutation must be between 11 to NN and distinct.

在一行中输出 NN 个整数(每个整数之间用一个空格分隔),表示 NN 个整数的排列 BB,使得 diff(A,B)≥Ndiff(A, B) \ge N。提醒一下,排列中的所有元素必须在 11 到 NN 之间,且互不相同。

输入输出样例

  • 输入#1

    4
    1 3 2 4

    输出#1

    4 2 3 1
  • 输入#2

    2
    2 1

    输出#2

    1 2

说明/提示

Explanation for the sample input/output #1

With A=[1,3,2,4]A = [1, 3, 2, 4] and B=[4,2,3,1]B = [4, 2, 3, 1], diff(A,B)=∣1−4∣+∣3−2∣+∣2−3∣+∣4−1∣=3+1+1+3=8diff(A, B) = |1 - 4| + |3 - 2| + |2 - 3| + |4 - 1| = 3 + 1 + 1 + 3 = 8. Since 8≥48 \ge 4, [4,2,3,1][4, 2, 3, 1] is one of the valid output for this sample.

样例输入/输出 #1 的说明

对于 A=[1,3,2,4]A = [1, 3, 2, 4] 和 B=[4,2,3,1]B = [4, 2, 3, 1],有 diff(A,B)=∣1−4∣+∣3−2∣+∣2−3∣+∣4−1∣=3+1+1+3=8diff(A, B) = |1 - 4| + |3 - 2| + |2 - 3| + |4 - 1| = 3 + 1 + 1 + 3 = 8。由于 8≥48 \ge 4,因此 [4,2,3,1][4, 2, 3, 1] 是该样例的一个合法输出。

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

首页