Codeforces Round 965 (Div. 2) |
---|
Finished |
This is the hard version of the problem. The only difference is that $$$x=1$$$ in this version. You must solve both versions to be able to hack.
You are given two integers $$$n$$$ and $$$x$$$ ($$$x=1$$$). There are $$$n$$$ balls lined up in a row, numbered from $$$1$$$ to $$$n$$$ from left to right. Initially, there is a value $$$a_i$$$ written on the $$$i$$$-th ball.
For each integer $$$i$$$ from $$$1$$$ to $$$n$$$, we define a function $$$f(i)$$$ as follows:
For each integer $$$i$$$ from $$$x$$$ to $$$n$$$, you need to find $$$f(i)$$$.
The first line contains $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases.
The first line of each test case contains two integers $$$n$$$ and $$$x$$$ ($$$1 \leq n \leq 2 \cdot 10^5; x = 1$$$) — the number of balls and the smallest index $$$i$$$ for which you need to find $$$f(i)$$$.
The second line of each test case contains $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$) — the initial number written on each ball.
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
For each test case, output $$$n-x+1$$$ space separated integers on a new line, where the $$$j$$$-th integer should represent $$$f(x+j-1)$$$.
35 11 2 3 2 17 14 5 1 2 1 4 511 11 2 3 1 1 9 3 2 4 1 3
1 1 2 2 3 1 1 1 1 1 3 4 1 1 2 2 2 1 1 1 3 3 4
In the first test case, below are the possible values of $$$j$$$ for each $$$f(i)$$$ from $$$1$$$ to $$$n$$$.
Name |
---|