QOJ.ac

QOJ

実行時間制限: 15.0 s メモリ制限: 1024 MB 満点: 100 ハック可能 ✓

#17889. 战争中的生活

統計

Seokhwan国爆发了战争!Seokhwan国是一个巨大的二叉树形状的国家,由总共 $10^{100}$ 个城市组成,城市编号为 $1, 2, \cdots, 10^{100}$。Seokhwan国有 $10^{100} - 1$ 条道路,其中第 $i$ 条道路($1 \le i < 10^{100}$)连接城市 $\lfloor \frac{i+1}{2} \rfloor$ 和城市 $i + 1$,如下图所示:

总理温斯顿·小Seokhwan(\textit{Winston Agiseokhwan})肩负着拯救危机中的Seokhwan国的重大任务。由于Seokhwan国的敌国正极力破坏Seokhwan国的重要军事设施,为了保护Seokhwan国的国民,优先防御军队频繁往来的城市是行之有效的。Seokhwan国有 $N$ 个军营分布在不同的城市中,军营之间会为了传递物资或信息而往来。此时,如果一个城市满足以下条件之一,则称该城市是危险的:该城市有军营,或者存在两个不同的军营,它们之间的路径经过该城市。请注意,由于Seokhwan国是一棵树,且路径定义为不重复访问同一个城市,因此连接任意两个军营的路径总是唯一的。

为了帮助小Seokhwan总理,请计算Seokhwan国中危险城市的数量。

输入格式

第一行给出军营的数量 $N$。($2 \le N \le 250\,000$)

接下来的 $N$ 行,每行给出一个表示军营所在城市编号的序列 $A_1, A_2, \cdots, A_N$。给出的城市编号互不相同。($1 \le A_i < 2^{50}$)

输出格式

输出Seokhwan国中危险城市的数量。

样例

输入样例 1

4
4 5 6 7

输出样例 1

7

输入样例 2

2
1 4294967296

输出样例 2

33

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.