time limit per test2 seconds

memory limit per test256 megabytes

inputstandard input

outputstandard output

You are given a set Y of n distinct positive integers y1, y2, …, yn.

Set X of n distinct positive integers x1, x2, …, xn 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:

Take any integer xi and multiply it by two, i.e. replace xi with 2·xi.

Take any integer xi, multiply it by two and add one, i.e. replace xi with 2·xi + 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.

Input

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 y1, …, yn (1 ≤ yi ≤ 109), that are guaranteed to be distinct.

Output

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.

Examples

input

5

1 2 3 4 5

output

4 5 2 3 1

input

6

15 14 3 13 1 12

output

12 13 14 7 3 1

input

6

9 7 13 17 5 11

output

4 5 2 6 3 1

【题解】



把一个最大的数字一直除2并不可取。

可以想见。要让最大的数字最小。

每次只要对最大的数字进行处理一次就好了。

而你一直除2、除后的数字可能不是这段序列的最大值了。那样的改变是没有意义的。不会再改变整个数列的最大值。

用优先队列维护最大值。每次对最大值进行除2。如果除1次会重复,就一直除。如果除到0了就表示不能进行操作了。则直接返回这个经过处理后的数列。

优先队列可以直接用STL,默认最顶部为最大值。

判断有没有重复则用map;

以下是prioritySTL的用法

#include <algorithm>
#include <queue> using namespace std;
//·····
priority_queue<int> q;

这样做默认为单调递增的队列。即top为最大的元素;

如何改为单调递减的队列我下一篇文章会讲。

一下是完整代码。

#include <cstdio>
#include <algorithm>
#include <queue>
#include <map> using namespace std; priority_queue <int> q;
map <int, int> dic;
int n; int main()
{
//freopen("F:\\rush.txt", "r", stdin);
scanf("%d", &n);
for (int i = 1; i <= n; i++)
{
int x;
scanf("%d", &x);
q.push(x);
dic[x] = 1;
}
while (true)
{
int y = q.top();
while (dic[y] && y > 0)
y >>= 1;
if (y == 0)
break;
q.pop();
q.push(y);
dic[y] = 1;
}
bool flag = false;
while (!q.empty())
{
int x = q.top();
if (!flag)
printf("%d", x);
else
printf(" %d", x);
q.pop();
flag = true;
}
printf("\n");
return 0;
}

【53.57%】【codeforces 722D】Generating Sets的更多相关文章

  1. 【53.57%】【codeforces 610C】Harmony Analysis

    time limit per test3 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  2. 【 BowWow and the Timetable CodeForces - 1204A 】【思维】

    题目链接 可以发现 十进制4 对应 二进制100 十进制16 对应 二进制10000 十进制64 对应 二进制1000000 可以发现每多两个零,4的次幂就增加1. 用string读入题目给定的二进制 ...

  3. 【57.97%】【codeforces Round #380A】Interview with Oleg

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  4. 【34.57%】【codeforces 557D】Vitaly and Cycle

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  5. 【Educational Codeforces Round 53 (Rated for Div. 2) C】Vasya and Robot

    [链接] 我是链接,点我呀:) [题意] [题解] 如果|x|+|y|>n 显然.从(0,0)根本就没法到(x,y) 但|x|+|y|<=n还不一定就能到达(x,y) 注意到,你每走一步路 ...

  6. 【codeforces 750C】New Year and Rating(做法2)

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  7. 【codeforces 750A】New Year and Hurry

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  8. 【codeforces 750C】New Year and Rating

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  9. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

随机推荐

  1. 海康威视抓拍一体机--- C#源码

    https://pan.baidu.com/s/1kV4AjRp 需要的联系qq:694666781

  2. 洛谷——P3178 [HAOI2015]树上操作

    https://www.luogu.org/problem/show?pid=3178#sub 题目描述 有一棵点数为 N 的树,以点 1 为根,且树点有边权.然后有 M 个操作,分为三种:操作 1 ...

  3. iOS -读书笔记-网络请求

    知道"3次握手"吗?突然想起这个词 什么是3次握手? TCP三次握手/四次挥手详解 这里是3次握手的详解 3次握手就是为了可靠的传送数据,TCP(什么是TCP呢?TCP就是一种可靠 ...

  4. c、c++ 结构体的嵌套

    c.c++ 结构体的嵌套 /************************************************************************/ /* 嵌套结构体 * C ...

  5. php数组插入数据

    php数组插入数据 一.总结 代码要多敲,看是看不会的 php代码直接在页面不好敲,可以去控制器里面敲 二.目标 在一组数中,要求插入一个数,按其原来顺序插入,维护原来排序方式. 三.代码 (1).思 ...

  6. Web页面转换成Word文件,利用wordXML

    简介:处理流程表单数据以WordXML形式填充Word文档表格换行符丢失问题 //将前台收集的XML中“$”循环拆分成"<w:br/>" by pengyc 解决表格填 ...

  7. 提高IIS的FTP安全性 管理员的九阴真经

    提高IIS的FTP安全性 管理员的九阴真经 <九阴真经>是很多武林高手蒙昧以求的武林秘籍,在系统管理员这个武林中也有很多类似<九阴真经>一样的秘籍.在这里就向大家介绍一下有关提 ...

  8. Windows下多个Mysql实例配置主从

    序:     网上有很多类似的文章,也是各种百度出来的,但是对于多数刚开始接触MYSQL主从的小白来说,网上文章的代码里面很多技术点都没有理解,有跌打误撞碰上的,但多数都是这篇文章卡主了,换篇文章接着 ...

  9. Android开发工具之adt-bundle-windows

    adt-bundle-windows是非常久之前的android开发工具.是集成了ADT版本号的eclipse,可是里面并没有下载SDK.这个须要自己单独下载,这个工具适合刚開始学习的人使用. 由于刚 ...

  10. PHP版本 D-Link 动态域名客户端

    <?php /* * D-Link 动态域名客户端.主域名www.dlinkddns.com 和 www.dlinkddns.com.cn * 首先获取外网IP,若IP没有变化,则结束运行:否则 ...