#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 nn sequences numbered from 11 to nn: a1,a2,ana_1, a_2, \dots a_n. Each sequence has length m+1m + 1. The ii-th sequence aia_i satisfies the recurrence ai,j=ai,j1×ia_{i,j} = a_{i,j - 1} \times i, where 1jm1 \leq j \leq m. Fusu will tell you the first term ai,0a_{i,0} 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, nn and mm.
The next nn lines each contain one integer. The integer on line ii is the first term ai,0a_{i,0} of sequence aia_i.

Output Format

Output one line with nn integers. The ii-th integer is the index of the sequence that is the ii-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 2+1=32 + 1 = 3.

For the first sequence a1a_1:

  • Its first term is a1,0=1a_{1,0} = 1.
  • Using ai,j=ai,j1×ia_{i,j} = a_{i,j - 1} \times i with i=1,j=1i = 1, j = 1, we get a1,1=a1,0×1=1a_{1,1} = a_{1,0} \times 1 = 1.
  • Using ai,j=ai,j1×ia_{i,j} = a_{i,j - 1} \times i with i=1,j=2i = 1, j = 2, we get a1,2=a1,1×1=1a_{1,2} = a_{1,1} \times 1 = 1.

So sequence a1a_1 is 1,1,11, 1, 1.

For the second sequence a2a_2:

  • Its first term is a2,0=2a_{2,0} = 2.
  • Using ai,j=ai,j1×ia_{i,j} = a_{i,j - 1} \times i with i=2,j=1i = 2, j = 1, we get a2,1=a2,0×2=2×2=4a_{2,1} = a_{2,0} \times 2 = 2 \times 2 = 4.
  • Using ai,j=ai,j1×ia_{i,j} = a_{i,j - 1} \times i with i=2,j=2i = 2, j = 2, we get a2,2=a2,1×2=4×2=8a_{2,2} = a_{2,1} \times 2 = 4 \times 2 = 8.

So sequence a2a_2 is 2,4,82, 4, 8.

By lexicographical comparison, a1a_1 is the smallest sequence. Therefore the output is 11.

Explanation for Sample 2

Sequence a1a_1 is 1,1,1,11, 1, 1, 1, and sequence a2a_2 is 1,2,4,8-1, -2, -4, -8.

Constraints

This problem has 1010 test points. The information for each test point is shown in the table below:

Special constraint A: it is guaranteed that all ai,0a_{i,0} are equal.
Special constraint B: it is guaranteed that all ai,0a_{i,0} are pairwise distinct.

For all test points, it is guaranteed that 1n1051 \leq n \leq 10^5, 1m1091 \leq m \leq 10^9, and 1ai,01091 \leq |a_{i,0}| \leq 10^9.

Hint

To compare the lexicographical order of two sequences aia_i and aja_j, do the following:

Find the smallest index pp such that ai,paj,pa_{i,p} \neq a_{j,p}, and compare ai,pa_{i,p} and aj,pa_{j,p}:

  • If ai,p<aj,pa_{i,p} < a_{j,p}, then aia_i is lexicographically smaller than aja_j.
  • If ai,p>aj,pa_{i,p} > a_{j,p}, then aia_i is lexicographically larger than aja_j.

It can be proven that under the constraints of this problem, such a pp must exist.

Translated by ChatGPT 5