编程介的小学生 2017-10-10 12:38 采纳率: 20.5%
浏览 591
已采纳

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条回答

  • threenewbee 2017-10-29 12:49
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘