#P5584. 「SWTR-1」Sunny's Crystals
「SWTR-1」Sunny's Crystals
Description
Little has crystals. Each crystal has an attribute , which is the value of this crystal.
One day, Little came to Little 's home and asked Little to arrange the crystals into a sequence, and destroy all crystals whose value is .
However, due to the special property of this sequence, each destruction must satisfy:
- The crystal's position in the sequence must be a power of . That is, you can only destroy crystals at position , where and is an integer, and is the current number of crystals in the sequence.
After destroying one crystal, all crystals after it move forward by one position.
For example, for the value sequence , you can only destroy crystals at positions .
If you destroy the crystal at position , the sequence becomes .
To save time, Little wants to know the minimum number of destructions needed to destroy all crystals with value , and what the initial position of the destroyed crystal is for the -th destruction.
This problem uses Special Judge. If there are multiple answers, you may output any one of them.
Input Format
The first line contains two integers .
The second line contains positive integers .
Output Format
The first line contains an integer , meaning the minimum number of destructions needed to destroy all crystals with value .
The next line contains numbers. The -th number indicates the initial position of the crystal destroyed in the -th destruction, separated by spaces.
5 4
1 4 2 4 5
2
4 2
5 2
1 2 2 2 2
4
2 3 4 5
5 8
6 10 4 7 8
2
4 5
Hint
Sample Explanation
Sample :
First destroy the later , whose initial position is . The value sequence becomes: .
Then destroy the earlier , whose initial position is .
The total number of destructions is .
Sample :
First destroy the first , whose initial position is , and the sequence becomes: .
Then destroy the remaining first , whose initial position is , and the sequence becomes: .
Then destroy the first , whose initial position is , and the sequence becomes: .
Then destroy the first , whose initial position is .
The total number of destructions is .
Constraints and Notes
For of the testdata, .
For of the testdata, .
For of the testdata, .
For of the testdata, .
For of the testdata, .
For of the testdata, .
For of the testdata, . It is guaranteed that the number of is no more than .
The shattered crystals sparkle under the sunlight...
Translated by ChatGPT 5
京公网安备 11011102002149号