#P9472. [yLOI2022] 枕万梦
[yLOI2022] 枕万梦
Background
In the dim flow of years, stars shift and things change, singing praise of youth.
In the dim crowd, one glance sees through it all; sun and moon vanish without a trace.
In the dim fate between you and me, our hearts understand each other—far more than ten thousand dreams.
Forgetting ourselves in this long-awaited reunion.
In the dim world, clouds and mist surge; shoulders brush and people crowd.
In the dim chorus of all sounds, unwilling to stay silent, grand without end.
In the dim fate between you and me, sitting face to face across the ends of the earth, our “telepathy” (lingxi) stirs.
And we meet in a space and time just within reach.
Yin Lin, “Pillow of Ten Thousand Dreams”.
Background
Problem Description
Daybreak came. Fusu could not resist sleepiness and fell asleep early. In a gravity-less dream, Fusu encountered many floating sequences. They all have the same length, and they are all wonderful geometric sequences. By instinct, Fusu wants to sort these sequences in lexicographical order, but in the dream she lost the ability to think. Please help her.
More specifically, there are sequences numbered from to : . Each sequence has length . The -th sequence satisfies the recurrence , where . Fusu will tell you the first term of each sequence, and you need to help her sort these sequences in lexicographical order.
Input Format
The first line contains two integers, in order, and .
The next lines each contain one integer. The integer on line is the first term of sequence .
Output Format
Output one line with integers. The -th integer is the index of the sequence that is the -th smallest in lexicographical order.
2 2
1
2
1 2
2 3
1
-1
2 1
2 2
1
1
1 2
见附加文件中的 B4.in
见附加文件中的 B4.ans
Hint
Explanation for Sample 1
There are two sequences, each of length .
For the first sequence :
- Its first term is .
- Using with , we get .
- Using with , we get .
So sequence is .
For the second sequence :
- Its first term is .
- Using with , we get .
- Using with , we get .
So sequence is .
By lexicographical comparison, is the smallest sequence. Therefore the output is .
Explanation for Sample 2
Sequence is , and sequence is .
Constraints
This problem has test points. The information for each test point is shown in the table below:

Special constraint A: it is guaranteed that all are equal.
Special constraint B: it is guaranteed that all are pairwise distinct.
For all test points, it is guaranteed that , , and .
Hint
To compare the lexicographical order of two sequences and , do the following:
Find the smallest index such that , and compare and :
- If , then is lexicographically smaller than .
- If , then is lexicographically larger than .
It can be proven that under the constraints of this problem, such a must exist.
Translated by ChatGPT 5