A Heap of Heaps
Time limit2sMemory limit512 MB
For every k from 1 to n-1, treat the array as a k-ary heap and count how many nodes are smaller than their parent.
- Level
Medium7 of 10
- Topics
- Math, Brute force, Implementation
- Solved
- No attempts yet
Problem
You are given a sequence of n integers . Take the sequence as the node values of a k-ary heap and count the nodes that break the min-heap property.
A k-ary heap is a rooted tree in which an internal node has at most k children. The nodes are numbered 1 to n and node 1 is the root. Node v has nodes , , , as its children. A child whose number is greater than n does not exist, so only the last internal node can have fewer than k children.
Let be the parent of a node v that is not the root. Node v breaks the min-heap property when . For each , count the nodes that break the property.
Input
The first line contains an integer n ().
The second line contains the n integers of the sequence, separated by spaces ().
Output
Print integers on one line, separated by single spaces. The -th number is the count of nodes that break the min-heap property in the -ary heap. When there is no such k, so print nothing.
Note
The pictures below show the heaps for when and the sequence is . The red nodes break the min-heap property.
