CF2259C.101

入门

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

The score of an array bb of length mm is defined as the maximum length of a subarray of bb such that the first and last elements of the subarray are equal to 11 and all other elements in the subarray are equal to 00. Formally, the score of bb is equal to the maximum integer kk for which there exists an index ii such that:

  • 1≤i≤m−k+11 \leq i \leq m - k + 1
  • bi=bi+k−1=1b_i = b_{i+k-1} = 1
  • bi+1=bi+2=…=bi+k−2=0b_{i+1} = b_{i+2} = \ldots = b_{i+k-2} = 0

If there is no subarray meeting the requirements, the score of bb is 00.

You are given an array a1,a2,…,ana_1, a_2, \ldots, a_n, such that each element is equal to one of −1-1, 00, or 11. Replace each −1-1 with either a 00 or 11 such that the score of aa is maximal over all possible ways to replace the −1-1s in aa.

数组 bb(长度为 mm)的得分定义为:bb 中满足“子数组首尾元素均为 11,且中间所有元素均为 00”的最长子数组的长度。形式化地,bb 的得分等于最大的整数 kk,使得存在下标 ii 满足:

  • 1≤i≤m−k+11 \leq i \leq m - k + 1
  • bi=bi+k−1=1b_i = b_{i+k-1} = 1
  • bi+1=bi+2=…=bi+k−2=0b_{i+1} = b_{i+2} = \ldots = b_{i+k-2} = 0

若不存在满足要求的子数组,则 bb 的得分为 00。

给定一个数组 a1,a2,…,ana_1, a_2, \ldots, a_n,其中每个元素为 −1-1、00 或 11 之一。请将每个 −1-1 替换为 00 或 11,使得替换后数组 aa 的得分在所有可能的替换方式中达到最大。

输入格式

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

The first line of each test case contains nn (1≤n≤2⋅1051 \leq n \leq 2 \cdot 10^5) — the length of aa.

The second line of each test case contains a1,a2,…,ana_1, a_2, \ldots, a_n (ai∈−1,0,1a_i \in {-1, 0, 1}) — the array aa.

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

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

每个测试用例的第一行包含 nn(1≤n≤2⋅1051 \leq n \leq 2 \cdot 10^5)—— 数组 aa 的长度。

每个测试用例的第二行包含 a1,a2,…,ana_1, a_2, \ldots, a_n(其中 ai∈{−1,0,1}a_i \in \{-1, 0, 1\})—— 数组 aa。

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

输出格式

For each test case, output nn space separated integers representing aa after the −1-1s were replaced with 00s or 11s. If there are multiple possible solutions, output any.

对于每个测试用例,输出 nn 个以空格分隔的整数,表示将 aa 中的所有 −1-1 替换为 00 或 11 后的结果。如果存在多种可能的解,输出任意一个即可。

输入输出样例

  • 输入#1

    10
    6
    1 0 -1 0 0 1
    7
    0 -1 0 0 1 0 1
    5
    -1 0 0 -1 0
    4
    0 0 0 0
    1
    -1
    6
    1 0 1 0 0 -1
    7
    0 1 0 0 0 1 0
    6
    -1 -1 -1 -1 -1 -1
    7
    -1 0 1 -1 0 0 1
    3
    -1 0 0

    输出#1

    1 0 0 0 0 1
    0 1 0 0 1 0 1
    1 0 0 1 0
    0 0 0 0
    1
    1 0 1 0 0 1
    0 1 0 0 0 1 0
    1 0 0 0 0 1
    0 0 1 0 0 0 1
    1 0 0

说明/提示

In the first test case, we can change the only −1-1 to a 00, making a=[1,0,0,0,0,1]a = [1, 0, 0, 0, 0, 1]. Since the first and last elements of aa are equal to 11, and all other elements are 00, the score of aa is 66.

In the third test case, changing both −1-1s to 11s makes a=[1,0,0,1,0]a = [1, 0, 0, 1, 0], and the largest subarray that satisfies the conditions in the statement is from the 11-st index to the 44-th index.

In the fifth test case, we set the only −1-1 to 11, making a=[1]a = [1], meaning the largest subarray that satisfies the conditions in the statement is the full array.

在第一个测试用例中,我们可以将唯一的 −1-1 改为 00,从而得到 a=[1,0,0,0,0,1]a = [1, 0, 0, 0, 0, 1]。由于 aa 的首尾元素均为 11,且其余所有元素均为 00,因此 aa 的得分为 66。

在第三个测试用例中,将两个 −1-1 均改为 11,可得 a=[1,0,0,1,0]a = [1, 0, 0, 1, 0],此时满足题目所述条件的最长子数组是从第 11 个下标到第 44 个下标。

在第五个测试用例中,我们将唯一的 −1-1 设为 11,得到 a=[1]a = [1],这意味着满足题目所述条件的最长子数组即为整个数组。

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

首页