QOJ.ac

QOJ

حد الوقت: 2.0 s حد الذاكرة: 512 MB مجموع النقاط: 100 قابلة للهجوم ✓

#16790. 坏的 Treap

الإحصائيات

Treap(树堆),也被称为笛卡尔树(Cartesian tree),是一种在二叉搜索树中存储键值集合的数据结构。每个节点都由一个二元组 $(x, y)$ 表示。

节点的 $x$ 值是存储的键。它们遵循“二叉搜索树规则”:节点左子树中所有节点的 $x$ 值都小于该节点的 $x$ 值,而右子树中所有节点的 $x$ 值都大于该节点的 $x$ 值。

节点的 $y$ 值遵循“堆规则”:节点的 $y$ 值小于或等于其父节点的 $y$ 值。

每个创建的节点的 $y$ 值通常是根据某种分布随机选择的。这使得许多操作具有良好的平均时间复杂度。

由于这种数据结构结合了二叉搜索树和堆的一些性质,它的名字是一个由两个单词组成的“混成词”:TRee + hEAP = TREAP。

一个有 7 个节点的 Treap;其高度为 4

下方样例测试对应的 Treap

Benjamin 认为 $y$ 值选择过程中的非确定性是不好的,因为这会导致每次运行的执行时间不同。他决定根据每个节点的 $x$ 值确定性地计算其 $y$ 值。

他选择了规则 $y = \sin(x)$。他特别高兴的是,不同的整数 $x$ 总是会得到不同的 $y$。

Barbara 明白,虽然非确定性 Treap 在提供“坏”的随机序列时表现出最坏的性能,但确定性 Treap 在提供“坏”的键值集合时就会表现出最坏的性能。她想通过向 Benjamin 展示 $n$ 个整数键来向他解释这一点,这些键存储在他的数据结构中时,将形成一个高度为 $n$ 的 Treap —— 这是“最不平衡”的可能情况。

请通过提供 $n$ 个这样的键来帮助 Barbara。所有这些键都应该符合 32 位有符号整数类型。

输入格式

输入包含一个整数 $n$($1 \le n \le 50\,000$)。

输出格式

输出 $n$ 行,包含互不相同的整数键。所有键必须在 $-2^{31}$ 到 $2^{31} - 1$ 之间(含端点)。

使用规则 $y = \sin(x)$ 在这些键上构建的 Treap 的高度必须为 $n$。

样例

输入样例 1

4

输出样例 1

-2
0
-1
-4

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.