CF1839C.Insert Zero and Invert Prefix

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

You have a sequence a1,a2,,ana_1, a_2, \ldots, a_n of length nn , each element of which is either 00 or 11 , and a sequence bb , which is initially empty.

You are going to perform nn operations. On each of them you will increase the length of bb by 11 .

  • On the ii -th operation you choose an integer pp between 00 and i1i-1 . You insert 00 in the sequence bb on position p+1p+1 (after the first pp elements), and then you invert the first pp elements of bb .
  • More formally: let's denote the sequence bb before the ii -th ( 1in1 \le i \le n ) operation as b1,b2,,bi1b_1, b_2, \ldots, b_{i-1} . On the ii -th operation you choose an integer pp between 00 and i1i-1 and replace bb with b1,b2,,bp,0,bp+1,bp+2,,bi1\overline{b_1}, \overline{b_2}, \ldots, \overline{b_{p}}, 0, b_{p+1}, b_{p+2}, \ldots, b_{i-1} . Here, x\overline{x} denotes the binary inversion. Hence, 0=1\overline{0} = 1 and 1=0\overline{1} = 0 .

You can find examples of operations in the Notes section.

Determine if there exists a sequence of operations that makes bb equal to aa . If such sequence of operations exists, find it.

输入格式

Each test contains multiple test cases. The first line contains a single integer tt ( 1t1041 \le t \le 10^4 ) — the number of test cases.

The first line of each test case contains one integer nn ( 1n1051 \le n \le 10^5 ) — the length of the sequence aa .

The second line of each test case contains nn integers a1,a2,,ana_1, a_2, \ldots, a_n ( 0ai10 \le a_i \le 1 ) — the sequence aa .

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

输出格式

For each test case:

  • output "NO", if it is impossible to make bb equal to aa using the given operations;
  • otherwise, output "YES" in the first line and nn integers p1,p2,,pnp_1, p_2, \ldots, p_n ( 0pii10 \le p_i \le i-1 ) in the second line — the description of sequence of operations that makes bb equal to aa . Here, pip_i should be the integer you choose on the ii -th operation. If there are multiple solutions, you can output any of them.

输入输出样例

  • 输入#1

    4
    5
    1 1 0 0 0
    1
    1
    3
    0 1 1
    6
    1 0 0 1 1 0

    输出#1

    YES
    0 0 2 1 3
    NO
    NO
    YES
    0 1 0 2 4 2

说明/提示

In the first test case,

  1. Before the first operation, b=[]b = [\,] . You choose p=0p = 0 and replace bb with [0][\, \underline{0} \,]
  2. On the second operation you choose p=0p = 0 and replace bb with [0,0][\, \underline{0}, 0 \,] .
  3. On the third operation you choose p=2p = 2 and replace bb with [1,1,0][\, 1, 1, \underline{0} \,] .
  4. On the fourth operation you choose p=1p = 1 and replace bb with [0,0,1,0][\, 0, \underline{0}, 1, 0 \,] .
  5. On the fifth operation you choose p=3p = 3 and replace bb with [1,1,0,0,0][\, 1, 1, 0, \underline{0}, 0 \,] .

Hence, sequence bb changes in the following way: [][\,] p=0\xrightarrow{p \, = \, 0} [0][\, \underline{0} \,] p=0\xrightarrow{p \, = \, 0} [0,0][\, \underline{0}, 0 \,] p=2\xrightarrow{p \, = \, 2} [1,1,0][\, 1, 1, \underline{0} \,] p=1\xrightarrow{p \, = \, 1} [0,0,1,0][\, 0, \underline{0}, 1, 0 \,] p=3\xrightarrow{p \, = \, 3} [1,1,0,0,0][\, 1, 1, 0, \underline{0}, 0 \,] . In the end the sequence bb is equal to the sequence aa , so this way to perform operations is one of the correct answers.

In the second test case, n=1n = 1 and the only achiveable sequence bb is [0][\, 0 \, ] .

In the third test case, there are six possible sequences of operations:

  1. [][\,] p=0\xrightarrow{p \, = \, 0} [0][\, \underline{0} \,] p=0\xrightarrow{p \, = \, 0} [0,0][\, \underline{0}, 0 \,] p=0\xrightarrow{p \, = \, 0} [0,0,0][\, \underline{0}, 0, 0 \,] .
  2. [][\,] p=0\xrightarrow{p \, = \, 0} [0][\, \underline{0} \,] p=0\xrightarrow{p \, = \, 0} [0,0][\, \underline{0}, 0 \,] p=1\xrightarrow{p \, = \, 1} [1,0,0][\, 1, \underline{0}, 0 \,] .
  3. [][\,] p=0\xrightarrow{p \, = \, 0} [0][\, \underline{0} \,] p=0\xrightarrow{p \, = \, 0} [0,0][\, \underline{0}, 0 \,] p=2\xrightarrow{p \, = \, 2} [1,1,0][\, 1, 1, \underline{0} \,] .
  4. [][\,] p=0\xrightarrow{p \, = \, 0} [0][\, \underline{0} \,] p=1\xrightarrow{p \, = \, 1} [1,0][\, 1, \underline{0} \,] p=0\xrightarrow{p \, = \, 0} [0,1,0][\, \underline{0}, 1, 0 \,] .
  5. [][\,] p=0\xrightarrow{p \, = \, 0} [0][\, \underline{0} \,] p=1\xrightarrow{p \, = \, 1} [1,0][\, 1, \underline{0} \,] p=1\xrightarrow{p \, = \, 1} [0,0,0][\, 0, \underline{0}, 0 \,] .
  6. [][\,] p=0\xrightarrow{p \, = \, 0} [0][\, \underline{0} \,] p=1\xrightarrow{p \, = \, 1} [1,0][\, 1, \underline{0} \,] p=2\xrightarrow{p \, = \, 2} [0,1,0][\, 0, 1, \underline{0} \,] .

None of them makes bb equal to [0,1,1][\, 0, 1, 1 \,] , so the answer is "NO".

首页