CF1852E.Rivalries
NOI/NOI+/CTSC
通过率:0%
时间限制:2.00s
内存限制:512MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Ntarsis has an array a of length n.
The power of a subarray al…ar (1≤l≤r≤n) is defined as:
- The largest value x such that al…ar contains x and neither a1…al−1 nor ar+1…an contains x.
- If no such x exists, the power is 0.
Call an array b a rival to a if the following holds:
- The length of both a and b are equal to some n.
- Over all l,r where 1≤l≤r≤n, the power of al…ar equals the power of bl…br.
- The elements of b are positive.
Ntarsis wants you to find a rival b to a such that the sum of bi over 1≤i≤n is maximized. Help him with this task!
Ntarsis 有一个长度为 n 的数组 a。
子数组 al…ar(其中 1≤l≤r≤n)的力量值(power)定义如下:
- 最大的值 x,使得 x 出现在 al…ar 中,但不出现在 a1…al−1 中,也不出现在 ar+1…an 中;
- 若不存在这样的 x,则该子数组的力量值为 0。
若数组 b 满足以下条件,则称其为 a 的一个对手数组(rival):
- a 与 b 的长度均为某个 n;
- 对所有满足 1≤l≤r≤n 的 l,r,子数组 al…ar 的力量值等于子数组 bl…br 的力量值;
- b 的所有元素均为正整数。
Ntarsis 希望你为 a 找到一个对手数组 b,使得 ∑i=1nbi 最大。请帮助他完成这项任务!
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤105). The description of the test cases follows.
The first line of each test case has a single integer n (1≤n≤105).
The next line contains n integers a1,a2,…,an (1≤ai≤109).
It is guaranteed that the sum of n across all test cases does not exceed 2⋅105.
每个测试包含多个测试用例。第一行包含测试用例的数量 t(1≤t≤105)。随后是各测试用例的描述。
每个测试用例的第一行包含一个整数 n(1≤n≤105)。
下一行包含 n 个整数 a1,a2,…,an(1≤ai≤109)。
保证所有测试用例中 n 的总和不超过 2⋅105。
输出格式
For each test case, output n integers b1,b2,…,bn — a valid rival to a such that b1+b2+⋯+bn is maximal.
If there exist multiple rivals with the maximum sum, output any of them.
对于每个测试用例,输出 n 个整数 b1,b2,…,bn —— 这是一个关于 a 的合法对手序列,且满足 b1+b2+⋯+bn 的值最大。
若存在多个具有最大和的合法对手序列,则输出其中任意一个即可。
输入输出样例
输入#1
7 5 1 4 1 3 3 5 1 4 1 8 8 5 2 1 1 1 2 8 3 2 3 5 2 2 5 3 8 1 1 1 1 4 3 3 3 10 1 9 5 9 8 1 5 8 9 1 16 1 1 1 1 5 5 5 5 9 9 9 9 7 7 7 7
输出#1
2 4 2 3 3 3 4 3 8 8 2 1 2 1 2 4 2 4 5 5 2 5 4 1 2 2 1 4 3 2 3 7 9 5 9 8 9 5 8 9 7 1 8 8 1 5 8 8 5 9 9 9 9 7 8 8 7
说明/提示
For the first test case, one rival with the maximal sum is [2,4,2,3,3].
[2,4,2,3,3] can be shown to be a rival to [1,4,1,3,3].
All possible subarrays of a and b and their corresponding powers are listed below:
- The power of a[1:1]=[1]=0, the power of b[1:1]=[2]=0.
- The power of a[1:2]=[1,4]=4, the power of b[1:2]=[2,4]=4.
- The power of a[1:3]=[1,4,1]=4, the power of b[1:3]=[2,4,2]=4.
- The power of a[1:4]=[1,4,1,3]=4, the power of b[1:4]=[2,4,2,3]=4.
- The power of a[1:5]=[1,4,1,3,3]=4, the power of b[1:5]=[2,4,2,3,3]=4.
- The power of a[2:2]=[4]=4, the power of b[2:2]=[4]=4.
- The power of a[2:3]=[4,1]=4, the power of b[2:3]=[4,2]=4.
- The power of a[2:4]=[4,1,3]=4, the power of b[2:4]=[4,2,3]=4.
- The power of a[2:5]=[4,1,3,3]=4, the power of b[2:5]=[4,2,3,3]=4.
- The power of a[3:3]=[1]=0, the power of b[3:3]=[2]=0.
- The power of a[3:4]=[1,3]=0, the power of b[3:4]=[2,3]=0.
- The power of a[3:5]=[1,3,3]=3, the power of b[3:5]=[2,3,3]=3.
- The power of a[4:4]=[3]=0, the power of b[4:4]=[3]=0.
- The power of a[4:5]=[3,3]=3, the power of b[4:5]=[3,3]=3.
- The power of a[5:5]=[3]=0, the power of b[5:5]=[3]=0.
It can be shown there exists no rival with a greater sum than 2+4+2+3+3=14.
对于第一个测试用例,一个具有最大元素和的对手数组是 [2,4,2,3,3]。
可以验证 [2,4,2,3,3] 是 [1,4,1,3,3] 的一个对手数组。
数组 a 和 b 的所有可能子数组及其对应“能量值”(power)如下所列:
- a[1:1]=[1] 的能量值为 0,b[1:1]=[2] 的能量值为 0。
- a[1:2]=[1,4] 的能量值为 4,b[1:2]=[2,4] 的能量值为 4。
- a[1:3]=[1,4,1] 的能量值为 4,b[1:3]=[2,4,2] 的能量值为 4。
- a[1:4]=[1,4,1,3] 的能量值为 4,b[1:4]=[2,4,2,3] 的能量值为 4。
- a[1:5]=[1,4,1,3,3] 的能量值为 4,b[1:5]=[2,4,2,3,3] 的能量值为 4。
- a[2:2]=[4] 的能量值为 4,b[2:2]=[4] 的能量值为 4。
- a[2:3]=[4,1] 的能量值为 4,b[2:3]=[4,2] 的能量值为 4。
- a[2:4]=[4,1,3] 的能量值为 4,b[2:4]=[4,2,3] 的能量值为 4。
- a[2:5]=[4,1,3,3] 的能量值为 4,b[2:5]=[4,2,3,3] 的能量值为 4。
- a[3:3]=[1] 的能量值为 0,b[3:3]=[2] 的能量值为 0。
- a[3:4]=[1,3] 的能量值为 0,b[3:4]=[2,3] 的能量值为 0。
- a[3:5]=[1,3,3] 的能量值为 3,b[3:5]=[2,3,3] 的能量值为 3。
- a[4:4]=[3] 的能量值为 0,b[4:4]=[3] 的能量值为 0。
- a[4:5]=[3,3] 的能量值为 3,b[4:5]=[3,3] 的能量值为 3。
- a[5:5]=[3] 的能量值为 0,b[5:5]=[3] 的能量值为 0。
可以证明,不存在元素和大于 2+4+2+3+3=14 的对手数组。
输入解题思路,AI测评打分。不知道怎么写?