P28499 [洛谷] 「SWTR-1」Sunny's Crystals
提高
题目描述

Problem Background

Little $\mathrm{S}$ loves collecting crystals.

Problem Description

Little $\mathrm{S}$ has $n$ crystals, each with an attribute $d_i$, representing the value of the crystal.

One day, Little $\mathrm{A}$ visited Little $\mathrm{S}$'s home and asked him to arrange his crystals into a sequence and destroy all crystals with value $w$.

However, due to the special nature of this sequence, each destruction must satisfy:

  • The position of the crystal in the sequence must be a power of 2, i.e., you can only destroy crystals at positions $2^x$, where $0 \leq x \leq \log_2 y$ and $x$ is an integer, with $y$ being the current number of crystals in the sequence.

After destruction, all crystals behind the destroyed crystal will move forward by one position.

For example, given the sequence of crystal values $6\ 10\ 4\ 7\ 8$, you can only destroy crystals at positions $1, 2, 4$.

If you destroy the crystal at position $2$, the sequence will become $6\ 4\ 7\ 8$.

To save time, Little $\mathrm{S}$ wants to know the minimum number of times needed to destroy all crystals with value $w$, and the initial positions of the crystals destroyed each time.

This problem uses a Special Judge. If there are multiple correct answers, any one of them will be accepted.

Input Format

The first line contains two integers $n$ and $w$.

The second line contains $n$ positive integers $d_i$.

Output Format

The first line contains an integer $m$, representing the minimum number of times to destroy all crystals with value $w$.

The next line contains $m$ integers, where the $i$-th integer represents the initial position of the crystal destroyed in the $i$-th operation, separated by spaces.

Sample Input and Output

Sample Input #1

5 4
1 4 2 4 5

Sample Output #1

2
4 2

Sample Input #2

5 2
1 2 2 2 2

Sample Output #2

4
2 3 4 5

Sample Input #3

5 8
6 10 4 7 8

Sample Output #3

2
4 5

Notes

Sample Explanation

Sample $1$:

First, destroy the $4$ at the later position, with the initial position being $4$. The sequence becomes: $1\ 4\ 2\ 5$.

Then, destroy the $4$ at the earlier position, with the initial position being $2$.

The total number of operations is $2$.

Sample $2$:

First, destroy the first $2$, with the initial position being $2$. The sequence becomes: $1\ 2\ 2\ 2$.

Then, destroy the remaining first $2$, with the initial position being $3$. The sequence becomes: $1\ 2\ 2$.

Then, destroy the first $2$, with the initial position being $4$. The sequence becomes: $1\ 2$.

Finally, destroy the first $2$, with the initial position being $5$.

The total number of operations is $4$.

Data Range and Constraints

For $15\%$ of the data, $n \leq 5$.

For $25\%$ of the data, $n \leq 20$.

For $30\%$ of the data, $n \leq 1000$.

For $35\%$ of the data, $n \leq 10000$.

For $50\%$ of the data, $n \leq 3 \times 10^5$.

For $80\%$ of the data, $n \leq 10^6$.

For $100\%$ of the data, $1 \leq n \leq 3 \times 10^6$, $1 \leq d_i \leq 40000$, and the number of $w$ is guaranteed to be no more than $1.5 \times 10^6$.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
5 4 1 4 2 4 5
样例输出
2 4 2