#d1306. 树上逆序对
树上逆序对
Inversions on a Tree
Problem Description
For a rooted tree, define an inversion on the tree as an ordered pair satisfying , where denotes the parent of node .
For a -ary tree, the set of child indices of node is exactly all integers in .
Given the weights of nodes, for each compute the number of inversions on the tree when these nodes form a -ary tree.
Input Format
The first line contains an integer , the number of nodes ().
The second line contains integers , the node weights ().
Output Format
Output one line with integers, the numbers of inversions for respectively.
Sample Input
5
5 4 5 4 3
Sample Output
3 2 3 3