A9965 | A Heap of Heaps
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Andrew skipped lessons on the subject 'Algorithms and Data Structures' for the entire term. When he came to the final test, the teacher decided to give him a difficult task as a punishment.
The teacher gave Andrew an array of $n$ numbers $a_{1}$ , $...$ , $a_{n}$ . After that he asked Andrew for each $k$ from 1 to $n-1$ to build a $k$ -ary heap on the array and count the number of elements for which the property of the minimum-rooted heap is violated, i.e. the value of an element is less than the value of its parent.
Andrew looked up on the Wikipedia that a $k$ -ary heap is a rooted tree with vertices in elements of the array. If the elements of the array are indexed from 1 to $n$ , then the children of element $v$ are elements with indices $k(v-1)+2$ , $...$ , $kv+1$ (if some of these elements lie outside the borders of the array, the corresponding children are absent). In any $k$ -ary heap every element except for the first one has exactly one parent; for the element 1 the parent is absent (this element is the root of the heap). Denote $p(v)$ as the number of the parent of the element with the number $v$ . Let's say that for a non-root element $v$ the property of the heap is violated if $a_{v}<a_{p(v)}$ .
Help Andrew cope with the task!
The teacher gave Andrew an array of $n$ numbers $a_{1}$ , $...$ , $a_{n}$ . After that he asked Andrew for each $k$ from 1 to $n-1$ to build a $k$ -ary heap on the array and count the number of elements for which the property of the minimum-rooted heap is violated, i.e. the value of an element is less than the value of its parent.
Andrew looked up on the Wikipedia that a $k$ -ary heap is a rooted tree with vertices in elements of the array. If the elements of the array are indexed from 1 to $n$ , then the children of element $v$ are elements with indices $k(v-1)+2$ , $...$ , $kv+1$ (if some of these elements lie outside the borders of the array, the corresponding children are absent). In any $k$ -ary heap every element except for the first one has exactly one parent; for the element 1 the parent is absent (this element is the root of the heap). Denote $p(v)$ as the number of the parent of the element with the number $v$ . Let's say that for a non-root element $v$ the property of the heap is violated if $a_{v}<a_{p(v)}$ .
Help Andrew cope with the task!
输入格式
The first line contains a single integer $n$ ( $2<=n<=2·10^{5}$ ).
The second line contains $n$ space-separated integers $a_{1}$ , $...$ , $a_{n}$ ( $-10^{9}<=a_{i}<=10^{9}$ ).
The second line contains $n$ space-separated integers $a_{1}$ , $...$ , $a_{n}$ ( $-10^{9}<=a_{i}<=10^{9}$ ).
输出格式
in a single line print $n-1$ integers, separate the consecutive numbers with a single space — the number of elements for which the property of the $k$ -ary heap is violated, for $k=1$ , $2$ , $...$ , $n-1$ .
输入输出样例
输入 #1
5 1 5 4 3 2
输出 #1
3 2 1 0
输入 #2
6 2 2 2 2 2 2
输出 #2
0 0 0 0 0
Pictures with the heaps for the first sample are given below; elements for which the property of the heap is violated are marked with red.
In the second sample all elements are equal, so the property holds for all pairs.
In the second sample all elements are equal, so the property holds for all pairs.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted