Inventory

CodeForces - 569B

Companies always have a lot of equipment, furniture and other things. All of them should be tracked. To do this, there is an inventory number assigned with each item. It is much easier to create a database by using those numbers and keep the track of everything.

During an audit, you were surprised to find out that the items are not numbered sequentially, and some items even share the same inventory number! There is an urgent need to fix it. You have chosen to make the numbers of the items sequential, starting with 1. Changing a number is quite a time-consuming process, and you would like to make maximum use of the current numbering.

You have been given information on current inventory numbers for n items in the company. Renumber items so that their inventory numbers form a permutation of numbers from 1 to n by changing the number of as few items as possible. Let us remind you that a set of n numbers forms a permutation if all the numbers are in the range from 1 to n, and no two numbers are equal.

Input

The first line contains a single integer n — the number of items (1 ≤ n ≤ 105).

The second line contains n numbers a1, a2, ..., an (1 ≤ ai ≤ 105) — the initial inventory numbers of the items.

Output

Print n numbers — the final inventory numbers of the items in the order they occur in the input. If there are multiple possible answers, you may print any of them.

Examples

Input
3
1 3 2
Output
1 3 2 
Input
4
2 2 3 3
Output
2 1 3 4 
Input
1
2
Output
1 

Note

In the first test the numeration is already a permutation, so there is no need to change anything.

In the second test there are two pairs of equal numbers, in each pair you need to replace one number.

In the third test you need to replace 2 by 1, as the numbering should start from one.

sol:XJB乱构造,对于只出现一次的当然保留,否则替换成没出现过的,顺便把当前数字的出现次数-1

#include <bits/stdc++.h>
using namespace std;
typedef int ll;
inline ll read()
{
ll s=;
bool f=;
char ch=' ';
while(!isdigit(ch))
{
f|=(ch=='-'); ch=getchar();
}
while(isdigit(ch))
{
s=(s<<)+(s<<)+(ch^); ch=getchar();
}
return (f)?(-s):(s);
}
#define R(x) x=read()
inline void write(ll x)
{
if(x<)
{
putchar('-'); x=-x;
}
if(x<)
{
putchar(x+''); return;
}
write(x/);
putchar((x%)+'');
return;
}
#define W(x) write(x),putchar(' ')
#define Wl(x) write(x),putchar('\n')
const int N=;
int n,a[N],Ges[N],Shuz[N];
int main()
{
int i;
R(n);
for(i=;i<=n;i++)
{
Ges[a[i]=read()]++;
}
for(i=;i<=n;i++) if(!Ges[i]) Shuz[++*Shuz]=i;
int Now=;
for(i=;i<=n;i++)
{
if(a[i]<=n&&Ges[a[i]]==) W(a[i]);
else
{
W(Shuz[Now++]);
Ges[a[i]]--;
}
}
return ;
}
/*
input
3
1 3 2
output
1 3 2 input
4
2 2 3 3
output
2 1 3 4 input
1
2
output
1
*/

codeforces569B的更多相关文章

随机推荐

  1. 图片完全填充CardView区域

    在Android开发中,使用CardView来显示我们需要展示的图片,但是有时候显示出来的图片并没有填充整个CardView区域,为了让需要展示的图片填充整个CardView区域,只需要在ImageV ...

  2. Django:安装和启动

    最近在学习利用python语言进行web站点开发,使用的框架是Django.这篇博客主要介绍Django的安装和简单使用. 一.Django介绍 Django是一个开源的Web应用框架,由Python ...

  3. 完成了Coursera的一个机器学习课程

    终于完成了这个课程,从开始学习,到现在差不多过了一年的时间,中间由于一些原因耽搁了,最终还是完成了,记录一下!

  4. 企业IT架构转型之道,阿里巴巴中台战略思想与架构实战

    前言: 晚上11点多闲来无事,打开QQ技术群,发现有关 '中心化与引擎化' 的话题,本着学习的心态向大佬咨询,大佬推荐一本书,我大概看了有四分之一的样子,对于我这种对架构迷茫的人来说,如鱼得水,于是特 ...

  5. Beta阶段团队成员贡献分分配规则

    Beta阶段团队成员贡献分分配规则 Alpha阶段贡献分分配有些负责,在这里进行一些修改: 对任务完成得分部分进行了简化 对发现bug的惩罚措施进行了修改 移除了优化得分,不鼓励修改他人代码 移除了帮 ...

  6. Python练习-2

    #1.使用while循环输入 1 2 3 4 5 6 8 9 10 count = 0 while count < 10: count += 1 # count = count + 1 if c ...

  7. H5 40-CSS精灵图

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  8. html总结:float实现span和input输入框同行

    例: <input type="text" name="ytdwname" value="<%=user.getYtdwname() %& ...

  9. shell脚本--编写CGI代码(shell结合html)以及环境变量

    实现shell和html标签混合的方式编写代码: 推荐  初始CGI ,看完大概之后,大概对cgi有个大体的印象.下面是编写混合代码的示例: #!/bin/bash #index.cgi echo & ...

  10. 【转】Docker部署Tomcat及Web应用

    Docker部署Tomcat及Web应用 - Scofield_No1的博客 - CSDN博客https://blog.csdn.net/qq_32351227/article/details/786 ...