#P7912. [CSP-J 2021] 小熊的果篮

[CSP-J 2021] 小熊的果篮

Problem Description

In Little Bear’s fruit shop, there is a row of nn fruits. Each fruit is either an apple or an orange, numbered from left to right with positive integers 1,2,,n1, 2, \ldots, n. A consecutive segment of the same kind of fruit is called a “block”. Little Bear wants to pick the fruits in this row into several baskets. The method is as follows: each time, the leftmost fruit in every “block” is picked out simultaneously to form one basket. Repeat this operation until all fruits are picked.

Note that after picking one basket, the “blocks” may change. For example, if the only orange between two apple “blocks” is picked out, then the two apple “blocks” will merge into one “block”. Please help Little Bear determine which fruits are contained in each basket.

Input Format

The first line contains a positive integer nn, the number of fruits.

The second line contains nn integers separated by spaces. The ii-th number indicates the type of the fruit numbered ii: 11 represents an apple, and 00 represents an orange.

Output Format

Output several lines.

The ii-th line describes the basket formed by the ii-th picking operation. Output the indices of all fruits in that basket in increasing order, separated by one space between every two indices.

12
1 1 0 0 1 1 1 0 1 1 0 0

1 3 5 8 9 11
2 4 6 12
7
10

20
1 1 1 1 0 0 0 1 1 1 0 0 1 0 1 1 0 0 0 0

1 5 8 11 13 14 15 17
2 6 9 12 16 18
3 7 10 19
4 20

见附件中的 fruit/fruit3.in。
见附件中的 fruit/fruit3.ans。

Hint

Sample Explanation #1

This is the sample description for the first set of testdata.

Initially, the fruits are [1,1,0,0,1,1,1,0,1,1,0,0][1, 1, 0, 0, 1, 1, 1, 0, 1, 1, 0, 0], with a total of 66 blocks.

During the first picking operation, fruits numbered 1,3,5,8,9,111, 3, 5, 8, 9, 11 are picked out.

After that, the remaining fruits are [1,0,1,1,1,0][1, 0, 1, 1, 1, 0], with a total of 44 blocks.

During the second picking operation, fruits numbered 2,4,6,122, 4, 6, 12 are picked out.

After that, the remaining fruits are [1,1][1, 1], with only 11 block.

During the third picking operation, the fruit numbered 77 is picked out.

Finally, the remaining fruits are [1][1], with only 11 block.

During the fourth picking operation, the fruit numbered 1010 is picked out.

Constraints

For 10%10\% of the data, n5n \le 5.
For 30%30\% of the data, n1000n \le 1000.
For 70%70\% of the data, n50000n \le 50000.
For 100%100\% of the data, 1n2×1051 \le n \le 2 \times {10}^5.

Hint

Because the data size is large, C/C++ users are advised to use scanf and printf for input and output.

Translated by ChatGPT 5