CF722D.Generating Sets

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given a set Y of n distinct positive integers _y_1, _y_2, ..., y__n.

Set X of n distinct positive integers _x_1, _x_2, ..., x__n is said to generate set Y if one can transform X to Y by applying some number of the following two operation to integers in X:

  1. Take any integer x__i and multiply it by two, i.e. replace x__i with 2·x__i.
  2. Take any integer x__i, multiply it by two and add one, i.e. replace x__i with 2·x__i + 1.

Note that integers in X are not required to be distinct after each operation.

Two sets of distinct integers X and Y are equal if they are equal as sets. In other words, if we write elements of the sets in the array in the increasing order, these arrays would be equal.

Note, that any set of integers (or its permutation) generates itself.

You are given a set Y and have to find a set X that generates Y and the maximum element of X is mininum possible.

给你一个由 $ n $ 个互不相同的正整数组成的集合 $ Y = {y_1, y_2, \dots, y_n} $。

一个由 $ n $ 个互不相同的正整数组成的集合 $ X = {x_1, x_2, \dots, x_n} $ 被称为生成集合 $ Y $,当且仅当可以通过对 $ X $ 中的元素重复应用以下两种操作中的若干次(包括零次),将 $ X $ 变为 $ Y $:

  1. 选取任意一个整数 $ x_i $,将其乘以 2,即用 $ 2 \cdot x_i $ 替换 $ x_i $;
  2. 选取任意一个整数 $ x_i $,将其乘以 2 后加 1,即用 $ 2 \cdot x_i + 1 $ 替换 $ x_i $。

注意:每次操作后,$ X $ 中的整数不必保持互不相同。

两个由互不相同整数组成的集合 $ X $ 和 $ Y $ 被视为相等,当且仅当它们作为集合相等。换言之,若将两个集合的元素分别按升序排列成数组,则这两个数组完全相同。

注意:任意整数集合(或其任意排列)均可生成它自身。

现给你集合 $ Y $,你需要找出一个能生成 $ Y $ 的集合 $ X $,且使得 $ X $ 中的最大元素尽可能小。

输入格式

The first line of the input contains a single integer n (1 ≤ n ≤ 50 000) — the number of elements in Y.

The second line contains n integers _y_1, ..., y__n (1 ≤ y__i ≤ 109), that are guaranteed to be distinct.

输入的第一行包含一个整数 nn(1≤n≤50 0001 \leq n \leq 50\,000)—— 表示集合 YY 中的元素个数。

第二行包含 nn 个整数 y1,…,yny_1, \ldots, y_n(1≤yi≤1091 \leq y_i \leq 10^9),保证互不相同。

输出格式

Print n integers — set of distinct integers that generate Y and the maximum element of which is minimum possible. If there are several such sets, print any of them.

输出 n 个整数——即一组互不相同的整数,它们生成 Y,且其中最大元素尽可能小。若存在多组满足条件的集合,输出任意一组即可。

输入输出样例

  • 输入#1

    5
    1 2 3 4 5

    输出#1

    4 5 2 3 1
  • 输入#2

    6
    15 14 3 13 1 12

    输出#2

    12 13 14 7 3 1
  • 输入#3

    6
    9 7 13 17 5 11

    输出#3

    4 5 2 6 3 1

输入解题思路,AI测评打分。不知道怎么写?

首页