#abc274c. C - Ameba

C - Ameba

Score : 300300 points

问题描述

你观察了变形虫并记录了一些数据。

最初,有一只编号为 11 的变形虫。

你共记录了 NN 条数据。根据第 ii 条记录,编号为 AiA_i 的变形虫通过分裂自身,产生了两个新的变形虫,并分别编号为 2i2i2i+12i+1

此时,称变形虫 AiA_i 是变形虫 2i2i2i+12i+1 的父代。

对于每个 k=1,,2N+1k=1,\ldots,2N+1,变形虫 kk 距离变形虫 11 有多少代?

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

You observed amoebae and kept some records.

Initially, there was one amoeba, numbered 11.

You made NN records. According to the ii-th record, the amoeba numbered AiA_i disappeared by dividing itself into two new amoebae, which were then numbered 2i2i and 2i+12i+1. Here, amoeba AiA_i is said to be the parent of amoebae 2i2i and 2i+12i+1.

For each k=1,,2N+1k=1,\ldots,2N+1, how many generations away is amoeba kk from amoeba 11?

Constraints

  • 1N2×1051 \leq N \leq 2\times 10^5
  • The records are consistent. That is:
    • 1Ai2i11\leq A_i \leq 2i-1.
    • AiA_i are distinct integers.

Input

The input is given from Standard Input in the following format:

NN

A1A_1 A2A_2 \ldots ANA_N

Output

Print 2N+12N+1 lines. The kk-th line should contain the generation distance between amoeba 11 and amoeba kk.

Sample Input 1

2
1 2

Sample Output 1

0
1
1
2
2

From amoeba 11, amoebae 22 and 33 were born. From amoeba 22, amoebae 44 and 55 were born.

  • Amoeba 11 is zero generations away from amoeba 11.
  • Amoeba 22 is one generation away from amoeba 11.
  • Amoeba 33 is one generation away from amoeba 11.
  • Amoeba 44 is one generation away from amoeba 22, and two generations away from amoeba 11.
  • Amoeba 55 is one generation away from amoeba 22, and two generations away from amoeba 11.

Sample Input 2

4
1 3 5 2

Sample Output 2

0
1
1
2
2
3
3
2
2

update @ 2024/3/10 11:32:26