CF1916C.Training Before the Olympiad

普及-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Masha and Olya have an important team olympiad coming up soon. In honor of this, Masha, for warm-up, suggested playing a game with Olya:

There is an array aa of size nn. Masha goes first, and the players take turns. Each move is described by the following sequence of actions:

∙\bullet If the size of the array is 11, the game ends.

∙\bullet The player who is currently playing chooses two different indices ii, jj (1≤i,j≤∣a∣1 \le i, j \le |a|), and performs the following operation — removes aia_i and aja_j from the array and adds to the array a number equal to ⌊ai+aj2⌋⋅2\lfloor \frac{a_i + a_j}{2} \rfloor \cdot 2. In other words, first divides the sum of the numbers aia_i, aja_j by 22 rounding down, and then multiplies the result by 22.

Masha aims to maximize the final number, while Olya aims to minimize it.

Masha and Olya decided to play on each non-empty prefix of the initial array aa, and asked for your help.

For each k=1,2,…,nk = 1, 2, \ldots, n, answer the following question. Let only the first kk elements of the array aa be present in the game, with indices 1,2,…,k1, 2, \ldots, k respectively. What number will remain at the end with optimal play by both players?

玛莎和奥莉娅即将迎来一场重要的团队奥林匹克竞赛。为此,玛莎提议和奥莉娅玩一个热身游戏:

给定一个长度为 nn 的数组 aa。玛莎先手,双方轮流进行操作。每次操作按如下步骤进行:

∙\bullet 若当前数组长度为 11,则游戏结束。

∙\bullet 当前轮到行动的玩家选择两个不同的下标 ii, jj(满足 1≤i,j≤∣a∣1 \le i, j \le |a|),执行如下操作:从数组中移除 aia_i 和 aja_j,并向数组中加入一个新数 ⌊ai+aj2⌋⋅2\lfloor \frac{a_i + a_j}{2} \rfloor \cdot 2。换言之,先将 aia_i 与 aja_j 的和除以 22 并向下取整,再将结果乘以 22。

玛莎的目标是使最终剩余的数尽可能大,而奥莉娅的目标是使其尽可能小。

玛莎和奥莉娅决定在初始数组 aa 的每一个非空前缀上分别进行该游戏,并请求你的帮助。

对每个 k=1,2,…,nk = 1, 2, \ldots, n,回答以下问题:仅保留数组 aa 的前 kk 个元素(对应下标为 1,2,…,k1, 2, \ldots, k)参与游戏。在双方均采取最优策略的情况下,最终剩余的数是多少?

输入格式

The first line contains an integer tt (1≤t≤1041 \leq t \leq 10^4) — the number of test cases.

The first line of each test case contains a single integer nn (1≤n≤1051 \le n \le 10^5) — the size of the array.

The second line contains nn integers a1,a2,…,ana_1,a_2, \ldots,a_n (1≤ai≤1091 \leq a_i \leq 10^9) — the array on which Masha and Olya play.

It is guaranteed that the sum of nn over all test cases does not exceed 10510^5.

第一行包含一个整数 tt(1≤t≤1041 \leq t \leq 10^4)——测试用例的数量。

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

第二行包含 nn 个整数 a1,a2,…,ana_1,a_2, \ldots,a_n(1≤ai≤1091 \leq a_i \leq 10^9)——玛莎和奥莉娅进行游戏的数组。

保证所有测试用例的 nn 之和不超过 10510^5。

输出格式

For each test case, output nn integers. The kk-th of these numbers should be equal to the number that will remain at the end with optimal play by both players, on the array consisting of the first kk elements of the array aa.

对于每个测试用例,输出 nn 个整数。其中第 kk 个数应等于:在仅由数组 aa 的前 kk 个元素构成的数组上,双方均采取最优策略进行游戏后,最终剩余的数。

输入输出样例

  • 输入#1

    4
    1
    31
    6
    6 3 7 2 5 4
    3
    3 10 11
    5
    7 13 11 19 1

    输出#1

    31 
    6 8 16 18 22 26 
    3 12 24 
    7 20 30 48 50

说明/提示

In the third test case, for a prefix of length 11, the answer is 33. For a prefix of length 22, Masha has only one move, so the answer is 1212. For a prefix of length 33, Masha has three possible moves: she chooses 33 and 1010, then the final number is 2222, 33 and 1111, then the final number is 2424, 1010 and 1111, then the final number is 2222, so Masha will choose 33 and 1111 and get 2424.

在第三个测试用例中,对于长度为 11 的前缀,答案是 33;对于长度为 22 的前缀,玛莎只有唯一一种操作方式,因此答案是 1212;对于长度为 33 的前缀,玛莎有三种可能的操作:选择 33 和 1010,最终得到的数为 2222;选择 33 和 1111,最终得到的数为 2424;选择 1010 和 1111,最终得到的数为 2222。因此玛莎将选择 33 和 1111,得到 2424。

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

首页