CF1852E.Rivalries

NOI/NOI+/CTSC

通过率:0%

时间限制:2.00s

内存限制:512MB

AC君温馨提醒

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

题目描述

Ntarsis has an array aa of length nn.

The power of a subarray al…ara_l \dots a_r (1≤l≤r≤n1 \leq l \leq r \leq n) is defined as:

  • The largest value xx such that al…ara_l \dots a_r contains xx and neither a1…al−1a_1 \dots a_{l-1} nor ar+1…ana_{r+1} \dots a_n contains xx.
  • If no such xx exists, the power is 00.

Call an array bb a rival to aa if the following holds:

  • The length of both aa and bb are equal to some nn.
  • Over all l,rl, r where 1≤l≤r≤n1 \leq l \leq r \leq n, the power of al…ara_l \dots a_r equals the power of bl…brb_l \dots b_r.
  • The elements of bb are positive.

Ntarsis wants you to find a rival bb to aa such that the sum of bib_i over 1≤i≤n1 \leq i \leq n is maximized. Help him with this task!

Ntarsis 有一个长度为 nn 的数组 aa。

子数组 al…ara_l \dots a_r(其中 1≤l≤r≤n1 \leq l \leq r \leq n)的力量值(power)定义如下:

  • 最大的值 xx,使得 xx 出现在 al…ara_l \dots a_r 中,但不出现在 a1…al−1a_1 \dots a_{l-1} 中,也不出现在 ar+1…ana_{r+1} \dots a_n 中;
  • 若不存在这样的 xx,则该子数组的力量值为 00。

若数组 bb 满足以下条件,则称其为 aa 的一个对手数组(rival):

  • aa 与 bb 的长度均为某个 nn;
  • 对所有满足 1≤l≤r≤n1 \leq l \leq r \leq n 的 l,rl, r,子数组 al…ara_l \dots a_r 的力量值等于子数组 bl…brb_l \dots b_r 的力量值;
  • bb 的所有元素均为正整数。

Ntarsis 希望你为 aa 找到一个对手数组 bb,使得 ∑i=1nbi\sum_{i=1}^{n} b_i 最大。请帮助他完成这项任务!

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤1051 \le t \le 10^5). The description of the test cases follows.

The first line of each test case has a single integer nn (1≤n≤1051 \leq n \leq 10^5).

The next line contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (1≤ai≤1091 \leq a_i \leq 10^9).

It is guaranteed that the sum of nn across all test cases does not exceed 2⋅1052 \cdot 10^5.

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤1051 \le t \le 10^5)。随后是各测试用例的描述。

每个测试用例的第一行包含一个整数 nn(1≤n≤1051 \leq n \leq 10^5)。

下一行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(1≤ai≤1091 \leq a_i \leq 10^9)。

保证所有测试用例中 nn 的总和不超过 2⋅1052 \cdot 10^5。

输出格式

For each test case, output nn integers b1,b2,…,bnb_1, b_2, \ldots, b_n — a valid rival to aa such that b1+b2+⋯+bnb_1 + b_2 + \cdots + b_n is maximal.

If there exist multiple rivals with the maximum sum, output any of them.

对于每个测试用例,输出 nn 个整数 b1,b2,…,bnb_1, b_2, \ldots, b_n —— 这是一个关于 aa 的合法对手序列,且满足 b1+b2+⋯+bnb_1 + b_2 + \cdots + b_n 的值最大。

若存在多个具有最大和的合法对手序列,则输出其中任意一个即可。

输入输出样例

  • 输入#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].

[2,4,2,3,3][2, 4, 2, 3, 3] can be shown to be a rival to [1,4,1,3,3][1, 4, 1, 3, 3].

All possible subarrays of aa and bb and their corresponding powers are listed below:

  • The power of a[1:1]=[1]=0a[1:1] = [1] = 0, the power of b[1:1]=[2]=0b[1:1] = [2] = 0.
  • The power of a[1:2]=[1,4]=4a[1:2] = [1, 4] = 4, the power of b[1:2]=[2,4]=4b[1:2] = [2, 4] = 4.
  • The power of a[1:3]=[1,4,1]=4a[1:3] = [1, 4, 1] = 4, the power of b[1:3]=[2,4,2]=4b[1:3] = [2, 4, 2] = 4.
  • The power of a[1:4]=[1,4,1,3]=4a[1:4] = [1, 4, 1, 3] = 4, the power of b[1:4]=[2,4,2,3]=4b[1:4] = [2, 4, 2, 3] = 4.
  • The power of a[1:5]=[1,4,1,3,3]=4a[1:5] = [1, 4, 1, 3, 3] = 4, the power of b[1:5]=[2,4,2,3,3]=4b[1:5] = [2, 4, 2, 3, 3] = 4.
  • The power of a[2:2]=[4]=4a[2:2] = [4] = 4, the power of b[2:2]=[4]=4b[2:2] = [4] = 4.
  • The power of a[2:3]=[4,1]=4a[2:3] = [4, 1] = 4, the power of b[2:3]=[4,2]=4b[2:3] = [4, 2] = 4.
  • The power of a[2:4]=[4,1,3]=4a[2:4] = [4, 1, 3] = 4, the power of b[2:4]=[4,2,3]=4b[2:4] = [4, 2, 3] = 4.
  • The power of a[2:5]=[4,1,3,3]=4a[2:5] = [4, 1, 3, 3] = 4, the power of b[2:5]=[4,2,3,3]=4b[2:5] = [4, 2, 3, 3] = 4.
  • The power of a[3:3]=[1]=0a[3:3] = [1] = 0, the power of b[3:3]=[2]=0b[3:3] = [2] = 0.
  • The power of a[3:4]=[1,3]=0a[3:4] = [1, 3] = 0, the power of b[3:4]=[2,3]=0b[3:4] = [2, 3] = 0.
  • The power of a[3:5]=[1,3,3]=3a[3:5] = [1, 3, 3] = 3, the power of b[3:5]=[2,3,3]=3b[3:5] = [2, 3, 3] = 3.
  • The power of a[4:4]=[3]=0a[4:4] = [3] = 0, the power of b[4:4]=[3]=0b[4:4] = [3] = 0.
  • The power of a[4:5]=[3,3]=3a[4:5] = [3, 3] = 3, the power of b[4:5]=[3,3]=3b[4:5] = [3, 3] = 3.
  • The power of a[5:5]=[3]=0a[5:5] = [3] = 0, the power of b[5:5]=[3]=0b[5:5] = [3] = 0.

It can be shown there exists no rival with a greater sum than 2+4+2+3+3=142 + 4 + 2 + 3 + 3 = 14.

对于第一个测试用例,一个具有最大元素和的对手数组是 [2,4,2,3,3][2, 4, 2, 3, 3]。

可以验证 [2,4,2,3,3][2, 4, 2, 3, 3] 是 [1,4,1,3,3][1, 4, 1, 3, 3] 的一个对手数组。

数组 aa 和 bb 的所有可能子数组及其对应“能量值”(power)如下所列:

  • a[1:1]=[1]a[1:1] = [1] 的能量值为 00,b[1:1]=[2]b[1:1] = [2] 的能量值为 00。
  • a[1:2]=[1,4]a[1:2] = [1, 4] 的能量值为 44,b[1:2]=[2,4]b[1:2] = [2, 4] 的能量值为 44。
  • a[1:3]=[1,4,1]a[1:3] = [1, 4, 1] 的能量值为 44,b[1:3]=[2,4,2]b[1:3] = [2, 4, 2] 的能量值为 44。
  • a[1:4]=[1,4,1,3]a[1:4] = [1, 4, 1, 3] 的能量值为 44,b[1:4]=[2,4,2,3]b[1:4] = [2, 4, 2, 3] 的能量值为 44。
  • a[1:5]=[1,4,1,3,3]a[1:5] = [1, 4, 1, 3, 3] 的能量值为 44,b[1:5]=[2,4,2,3,3]b[1:5] = [2, 4, 2, 3, 3] 的能量值为 44。
  • a[2:2]=[4]a[2:2] = [4] 的能量值为 44,b[2:2]=[4]b[2:2] = [4] 的能量值为 44。
  • a[2:3]=[4,1]a[2:3] = [4, 1] 的能量值为 44,b[2:3]=[4,2]b[2:3] = [4, 2] 的能量值为 44。
  • a[2:4]=[4,1,3]a[2:4] = [4, 1, 3] 的能量值为 44,b[2:4]=[4,2,3]b[2:4] = [4, 2, 3] 的能量值为 44。
  • a[2:5]=[4,1,3,3]a[2:5] = [4, 1, 3, 3] 的能量值为 44,b[2:5]=[4,2,3,3]b[2:5] = [4, 2, 3, 3] 的能量值为 44。
  • a[3:3]=[1]a[3:3] = [1] 的能量值为 00,b[3:3]=[2]b[3:3] = [2] 的能量值为 00。
  • a[3:4]=[1,3]a[3:4] = [1, 3] 的能量值为 00,b[3:4]=[2,3]b[3:4] = [2, 3] 的能量值为 00。
  • a[3:5]=[1,3,3]a[3:5] = [1, 3, 3] 的能量值为 33,b[3:5]=[2,3,3]b[3:5] = [2, 3, 3] 的能量值为 33。
  • a[4:4]=[3]a[4:4] = [3] 的能量值为 00,b[4:4]=[3]b[4:4] = [3] 的能量值为 00。
  • a[4:5]=[3,3]a[4:5] = [3, 3] 的能量值为 33,b[4:5]=[3,3]b[4:5] = [3, 3] 的能量值为 33。
  • a[5:5]=[3]a[5:5] = [3] 的能量值为 00,b[5:5]=[3]b[5:5] = [3] 的能量值为 00。

可以证明,不存在元素和大于 2+4+2+3+3=142 + 4 + 2 + 3 + 3 = 14 的对手数组。

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

首页