409782: GYM103741 L WA Sorting
Description
On December 4th, ICPC2021 Nanjing was held. During the contest, Walk_alone (abbr. WA) did nothing but be stuck by Problem D, which was an easy data structure problem with a background of an adapted bubble sort. So he has being scolded by his teammates for a long time for losing a gold medal.
Today, his teammates gave him another adjusted sorting algorithm to help him overcome his psychological shadow. But his dread and fear stops him from even thinking about this problem. Help him solve the problem below to avoid being scolded by his teammates again!
Its pseudo-code is shown below.
Obviously not every sequence can be sorted by this algorithm, but it does not matter, and here comes the question:
Given a permutation $$$A=\{a_1,a_2,\cdots, a_n\}$$$. Let $$$A_k=\{a_1,a_2,\cdots, a_k\}$$$. Your task is to count the total number of times $$$m$$$ is assigned if we call $$${\rm SORT}(A_k)$$$ for every $$$k \ (1 \le k \le n)$$$.
InputThe first line contains an integer $$$n\ (1\le n\le 10^6)$$$ indicating the length of the sequence.
The second line contains $$$n$$$ integers $$$a_1,a_2,\cdots, a_n\ (1\le a_i\le n)$$$ indicating the given permutation.
OutputOutput one line containing $$$n$$$ integers $$$s_1,s_2,\cdots, s_n$$$ separated by a space, where $$$s_i$$$ indicates the total number of times $$$m$$$ is assigned if we call $$${\rm SORT}(A_i)$$$.
ExamplesInput6 5 4 2 6 3 1Output
1 4 8 11 13 19Input
6 4 5 2 3 6 1Output
1 3 6 8 13 17