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. redis学习(二)——String数据类型

    一.概述 字符串类型是Redis中最为基础的数据存储类型,它在Redis中是二进制安全的,这便意味着该类型可以接受任何格式的数据,如JPEG图像数据或Json对象描述信息等.在Redis中字符串类型的 ...

  2. JVM-自动内存管理机制

    关于GC: 垃圾收集通常被称为"GC",经过半个世纪的发展,内存动态分配与内存回收技术已经相当成熟.那我们为何还要了解GC和内存分配呢? 当我们需要排除各种内存溢出.内存泄露问题时 ...

  3. tkinter python(图形开发界面)

    Tkinter模块("Tk 接口")是Python的标准Tk GUI工具包的接口.Tk和Tkinter可以在大多数的Unix平台下使用,同样可以应用在Windows和Macinto ...

  4. 阻止form表单中的input按下回车时提交表单

    给form加属性:onsubmit="return false;"

  5. android linux 传文件

    EStrongs File Explorer 即: Es文件浏览器 网络 -> 远程管理器 设置 ->设置根目录 linux 使用浏览器访问即可.

  6. mysql创建数据库命令

    CREATE DATABASE IF NOT EXISTS yourdbname DEFAULT CHARSET utf8 COLLATE utf8_general_ci;

  7. 我们为什么要使用List和Set(List,Set详解)

    1.集合概述 类图 集合和数组的区别? 集合基本方法 集合特有的遍历方式? public static void main(String[] args) { //创建集合对象 Collection c ...

  8. MYSQL 创建数据库SQL

    CREATE DATABASE crm CHARACTER SET utf8 COLLATE utf8_general_ci; MySQL :: MySQL 5.7 Reference Manual ...

  9. asp.net mvc5 action多个参数

    需要完成http://site.com/user/add/1/2这样的url解析 使用action的参数直接获取数据的方式 Action声明如下 ) { ViewBag.clubID = id; ) ...

  10. react的项目坑

    首先在构造页面时 应该将页面的结构分析好. 在处理数据异步时 将数据结构进行完全的简单结构化. 使用redux时 注意返回的数据是深拷贝还是浅拷贝 否则会产生 数组不为空但是没有值的问题 使用自制数据 ...