Key Insertion

Description

As an employee of the Macrohard Company, you have been asked to implement the new data structure that would be used to store some integer keys.
The keys must be stored in a special ordered collection that can be considered as an array A, which has an infinite number of locations, numbered starting from 1. Initially all locations are empty. The following operation must be supported by the collection: Insert(L, K), where L is the location in the array and K is some positive integer value.
The operation must be processed as follows:
If A[L] is empty, set A[L] ← K.
If A[L] is not empty, perform Insert(L + 1, A[L]) and after that set A[L] ← K.

Given N integer numbers L1 , L2 , . . . , LN you have to output the contents of the array after a sequence of the following operations:
Insert(L1 , 1)
Insert(L2 , 2)
. . .
Insert(LN , N)
Input

The first line of the input file contains N --- the number of Insert operations and M --- the maximal position that can be used in the Insert operation (1 <= N <= 131 072, 1 <= M <= 131 072).
Next line contains N integer numbers L i that describe Insert operations to be performed (1 <= Li <= M ).
Output

Output the contents of the array after a given sequence of Insert operations. On the first line print W --- the number of the greatest location that is not empty. After that output W integer numbers --- A[1], A[2], . . . , A[W ]. Output zeroes for empty locations.
Sample Input

5 4
3 3 4 1 3
Sample Output

6
4 0 5 2 3 1

1个回答

Key Insertion
-

-
K-th Number 怎么求解
-
K-th Number
-

-

-

-

-

GitHub开源的10个超棒后台管理面板

100 个网络基础知识普及，看完成半个网络高手

C语言实现推箱子游戏

Java 的每个基本类型都对应了一个包装类型，比如说 int 的包装类型为 Integer，double 的包装类型为 Double。基本类型和包装类型的区别主要有以下 4 点。
C语言这么厉害，它自身又是用什么语言写的？

SpringBoot注解梳理

2019年10月全国程序员工资统计，一半以上的职位5个月没招到人。

Java 网络爬虫，就是这么的简单

58道JavaScript题，看看你能全对不？

“我想学习人工智能与机器学习，该从何做起？”

Java 爬虫遇到需要登录的网站，该怎么办？