There is a special number sequence which has n+1 integers. For each number in sequence, we have two rules:

● a i ∈ 0,n0,n

● a i ≠ a j( i ≠ j )

For sequence a and sequence b, the integrating degree t is defined as follows(“�” denotes exclusive or):

t = (a 0 � b 0) + (a 1 � b 1) +・・・+ (a n � b n)

(sequence B should also satisfy the rules described above)

Now give you a number n and the sequence a. You should calculate the maximum integrating degree t and print the sequence b.

Input

There are multiple test cases. Please process till EOF.

For each case, the first line contains an integer n(1 ≤ n ≤ 10 5), The second line contains a 0,a 1,a 2,…,a n.

Output

For each case, output two lines.The first line contains the maximum integrating degree t. The second line contains n+1 integers b 0,b 1,b 2,…,b n. There is exactly one space between b i and b i+1 (0 ≤ i ≤ n - 1). Don’t ouput any spaces after b n.

Sample Input

4

2 0 1 4 3

Sample Output

20

1 0 2 3 4

#include<map>
#include<set>
#include<queue>
#include<stack>
#include<vector>
#include<math.h>
#include<cstdio>
#include<sstream>
#include<numeric>//STL数值算法头文件
#include<stdlib.h>
#include <ctype.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<functional>//模板类头文件
using namespace std; typedef long long ll;
const int maxn=110000;
const int INF=0x3f3f3f3f; ll a[maxn];
ll d[maxn];
int main()
{
ll n;
while(~scanf("%I64d",&n))
{
for(ll i=0; i<=n; i++)
scanf("%I64d",&a[i]);
memset(d,-1,sizeof(d));
ll ans=0;
for(ll i=n; i>=0; i--)
{
ll t=0;
if(d[i]==-1)
{
for(ll j=0;; j++)
{
if(!(i&(1<<j))) t+=(1<<j);
if(t>=i)
{
t-=(1<<j);
break;
}
}
ans+=(i^t)*2;
d[i]=t;
d[t]=i;
}
}
printf("%I64d\n",ans);
for(ll i=0; i<=n; i++)
printf(i==n?"%I64d\n":"%I64d ",d[a[i]]);
}
return 0;
}

Number Sequence HDU - 5014的更多相关文章

  1. (KMP 模板)Number Sequence -- Hdu -- 1711

    http://acm.hdu.edu.cn/showproblem.php?pid=1711 Number Sequence Time Limit: 10000/5000 MS (Java/Other ...

  2. AC日记——Number Sequence hdu 1711

    Number Sequence Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  3. Number Sequence(HDU 1005 构造矩阵 )

    Number Sequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

  4. Number Sequence HDU 1711(KMP)

    http://acm.hdu.edu.cn/showproblem.php?pid=1711 首次接触KMP,自己都不是特别理解.在网上百度看了好几个帖子之后,对KMP也有了初步的理解. #inclu ...

  5. Number Sequence - HDU 1711(KMP模板题)

    题意:给你一个a串和一个b串,问b串是否是a串的子串,如果是返回b在a中最早出现的位置,否则输出-1   分析:应该是最简单的模板题了吧..... 代码如下: ==================== ...

  6. Number Sequence HDU 1711 KMP 模板

    题目大意:两个数组匹配,求子串首次出现的位置. 题目思路:数组长度,比较大,朴素算法的时间复杂度为 m*n超时.KMP的时间复杂度为m+n可行. #include<iostream> #i ...

  7. Spring-1-H Number Sequence(HDU 5014)解题报告及测试数据

    Number Sequence Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Pro ...

  8. ACM学习历程——HDU 5014 Number Sequence (贪心)(2014西安网赛)

    Description There is a special number sequence which has n+1 integers. For each number in sequence, ...

  9. HDU 1711 Number Sequence(数列)

    HDU 1711 Number Sequence(数列) Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Ja ...

随机推荐

  1. activemq依赖包获取

    现在项目中使用的是activemq-all.jar的jar,17M多,里面集成了日志.spring等相关的包.但项目启动时发现系统使用的是activemq包中的日志实现,没有用本项目的日志包.只能将整 ...

  2. git设置免密码登录

    设置用户名和邮箱 git config --global user.name "<username>" git config --global user.email & ...

  3. 两小时快速构建微信小程序

    小程序在2017年1月上线之初,被社会极力吹捧,刻意去将其制造为一个“风口”,透支其价值.但是在之后一个月里,石破天惊迅速归为沉寂.媒体又开始过度消费小程序,大谈其鸡肋之处. 个人认为小程序的一个分水 ...

  4. JS的prototype和__proto__

    一.prototype和__proto__的概念 prototype是函数的一个属性(每个函数都有一 个prototype属性),这个属性是一个指针,指向一个对象.它 是显示修改对象的原型的属性. _ ...

  5. sqlserver 树形结构表查询 获取拼接结果

    树形表结构如下 IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[Test]') AND ty ...

  6. Django rest framework + Vue简单示例

    构建vue项目参考这篇文章https://segmentfault.com/a/1190000008049815 一.创建Vue项目 修改源:npm config set registry https ...

  7. linux-open-source-development-tools【重点】

    https://www.pluralsight.com/blog/software-development/linux-open-source-development-tools https://ww ...

  8. mysql utf8改utf8mb4

    由于需要用到utf8mb4,之前是utf8现在给改成utf8mb4 查看当前环境 SHOW VARIABLES WHERE Variable_name LIKE 'character\_set\_%' ...

  9. python--lxml

    ''' xpath语法: /:在子节点里面找 //:在子子孙孙里面找 //div:查找当前网页的所有div标签 //div/p:先查找所有div标签,再找div的子标签中的p标签 //div//p:现 ...

  10. Internet Explorer 浏览器在同一时刻只能从同一域名下载两个文件。

    Internet Explorer 浏览器在同一时刻只能从同一域名下载两个文件.至于原因请见 MSDN Blogs:<Internet Explorer and Connection Limit ...