编程介的小学生 2017-05-02 15:41 采纳率: 20.5%
浏览 719
已采纳

Key Insertion

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 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 Li 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.

This problem contains multiple test cases!

The first line of a multiple input is an integer N, then a blank line followed by N input blocks. Each input block is in the format indicated in the problem description. There is a blank line between input blocks.

The output format consists of N output blocks. There is a blank line between output blocks.

Sample Input

1

5 4
3 3 4 1 3

Sample Output

6
4 0 5 2 3 1

  • 写回答

2条回答 默认 最新

  • threenewbee 2017-05-03 15:48
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题