#P9741. 「KDOI-06-J」翻转与反转

    ID: 9739 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 3 上传者: 标签>模拟数学2023洛谷原创O2优化洛谷月赛分类讨论

「KDOI-06-J」翻转与反转

Problem Description

Little W has a 0101 sequence a1,a2,,ana_1,a_2,\ldots,a_n of length nn. He will perform nn operations on this sequence in order.

In the ii-th operation (1in1\le i\le n), Little W will perform the following two transformations in order:

  1. Reverse the numbers in the interval [1,i][1,i] by index. Formally, after this transformation, the sequence aa becomes $a_i,a_{i-1},\ldots,a_{1},a_{i+1},a_{i+2},\ldots,a_n$.
  2. Flip the numbers in the interval [1,i][1,i] by value. Formally, after this transformation, for any 1ji1\le j\le i, if aj=0a_j=0 then aja_j becomes 11, otherwise aja_j becomes 00.

Little W wants to know the value of each element in the sequence aa after all nn operations are finished.

Input Format

Read input from standard input.

The first line contains a positive integer nn, representing the length of the sequence.

The next line contains nn integers, representing the sequence a1,a2,,ana_1,a_2,\ldots, a_n. It is guaranteed that ai=0a_i=0 or 11.

Output Format

Write output to standard output.

Output one line with nn integers, representing the value of each element in the sequence aa after all operations.

3
1 1 1

0 0 1 

8
1 0 1 1 1 0 0 1

0 1 0 1 1 1 1 0 

Hint

[Sample Explanation #1]

The changes of sequence aa are shown in the table below:

Operation count Changes of sequence aa
11 [1,1,1][1,1,1][0,1,1][1,1,1]\to [1,1,1]\to[0,1,1]
22 [0,1,1][1,0,1][0,1,1][0,1,1]\to [1,0,1]\to[0,1,1]
33 [0,1,1][1,1,0][0,0,1][0,1,1]\to [1,1,0]\to[0,0,1]

[Sample Explanation #2]

The changes of sequence aa are shown in the table below:

Operation count Sequence aa after the operation
- [1,0,1,1,1,0,0,1][1,0,1,1,1,0,0,1]
11 [0,0,1,1,1,0,0,1][0,0,1,1,1,0,0,1]
22 [1,1,1,1,1,0,0,1][1,1,1,1,1,0,0,1]
33 [0,0,0,1,1,0,0,1][0,0,0,1,1,0,0,1]
44 [0,1,1,1,1,0,0,1][0,1,1,1,1,0,0,1]
55 [0,0,0,0,1,0,0,1][0,0,0,0,1,0,0,1]
66 [1,0,1,1,1,1,0,1][1,0,1,1,1,1,0,1]
77 [1,0,0,0,0,1,0,1][1,0,0,0,0,1,0,1]
88 [0,1,0,1,1,1,1,0][0,1,0,1,1,1,1,0]

[Sample #3]

See revflip/revflip3.in and revflip/revflip3.ans in the contestant files.

[Sample #4]

See revflip/revflip4.in and revflip/revflip4.ans in the contestant files.

[Constraints]

For all data, it is guaranteed that 1n2×1061\le n\le 2\times 10^6, and for any 1in1\le i\le n, ai=0a_i=0 or 11.

Test point ID nn\le Special property
131\sim 3 10310^3 None
454\sim 5 10510^5
676 \sim 7 2×1062\times 10^6 ai=0a_i=0
8108\sim 10 None

Translated by ChatGPT 5