luogu#P10393. 无限循环?

    ID: 8283 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 3 上传者: 标签>2024洛谷原创Special JudgeO2优化洛谷月赛

无限循环?

Background

You are a little frog.

You are locked into the “Saila Feiwuzhi Prison”.

Life feels a bit depressing, so the little frog imagines that he has walked out of the Saila Feiwuzhi Prison.

Life becomes too depressing, so the little frog starts to resist the Saila Feiwuzhi Prison.

The little frog is helpless and isolated, and gets locked into the Saila Feiwuzhi Prison again.

...

The loop is not infinite. Repeating like this, one day he will break through the dark cage called Saila Feiwuzhi!

Problem Description

The little frog is temporarily trapped in a loop. This loop can be seen as a cycle with nn vertices (nn is odd). Each vertex ii has a vertex weight aia_i.

For all 1i<n1 \leq i < n, there is an edge between vertex ii and vertex i+1i+1 with edge weight wiw_i. There is also an edge between vertex 11 and vertex nn with edge weight wnw_n.

The edge weights and vertex weights have a special relationship: for any edge ii, its edge weight wiw_i must satisfy wi=12(ai+ai+1)w_i=\dfrac12(a_i+a_{i+1}), where wn=12(a1+an)w_n=\dfrac12(a_1+a_{n}). When the edge weight of any edge in the cycle changes, all vertex weights will change accordingly, until all vertex weights and edge weights satisfy the relationship above.

Now the frog knows the values of w1wnw_1 \sim w_n, and he can swap the weights of any two edges any number of times (i.e., he may permute the edge weights arbitrarily). The frog now needs to give two arrangements of w1wnw_1 \sim w_n, such that the weight of vertex 11 is maximized among all permutations / minimized among all permutations, respectively.

However, because the frog is stuck in an infinite loop, his mind is very confused. So he asks you for help: you need to construct these two arrangements.

It is guaranteed that n\boldsymbol n is odd.

Input Format

The first line contains an integer nn.

The second line contains nn integers. The ii-th number wiw_i represents the weight of the ii-th edge.

Output Format

Output two lines. Each line contains nn integers representing an answer.

The first line contains nn integers w1wnw_1' \sim w_n', representing an arrangement that makes the weight of vertex 11 as large as possible.

The second line contains nn integers w1wnw_1'' \sim w_n'', representing an arrangement that makes the weight of vertex 11 as small as possible.

This problem uses special judge. That is, if there are multiple valid answers, you may output any one of them.

3
0 0 0
0 0 0 
0 0 0
5
1 1 1 1 -1
1 1 1 -1 1 
1 1 -1 1 1
3
1 2 3
3 1 2
2 3 1

Hint

[Sample #1 Explanation]

Here, red numbers are vertex weights, black numbers are edge weights, and blue numbers are vertex indices.

It can be proved that in this arrangement, the weight of vertex 11 is both the minimum and the maximum.

[Sample #2 Explanation]

Here, red indicates vertex weights, black indicates edge weights, and blue indicates vertex indices.

It can be proved that in these two arrangements, the weight of vertex 11 reaches the maximum and the minimum respectively. Note that this is not necessarily the unique solution.


[Constraints and Notes]

This problem uses bundled testdata.

Subtask\text{Subtask} Constraints Score Special Property
11 n=3n=3 2020 A\rm A
22 None
33 n106n\leq 10^6 B\rm B
44 C\rm C
55 None
  • Special Property A\rm A: it is guaranteed that {w}\{w\} is a sequence obtained by arbitrarily permuting {1,0,1}\{-1,0,1\}.
  • Special Property B\rm B: it is guaranteed that n3n \ge 3, and for all i[2,n]i\in [2,n], wiw_i are the same.
  • Special Property C\rm C: it is guaranteed that n3n\ge 3, and for all i[3,n]i\in [3,n], wiw_i are the same.
  • For 100%100\% of the testdata, 1n1061\leq n\leq 10^6 and nn is odd, and wi109|w_i|\leq 10^9.

Translated by ChatGPT 5