CF1523C.Compression and Expansion

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

William is a huge fan of planning ahead. That is why he starts his morning routine by creating a nested list of upcoming errands.

A valid nested list is any list which can be created from a list with one item "1" by applying some operations. Each operation inserts a new item into the list, on a new line, just after one of existing items a1 . a2 . a3 .  ⋯  . aka_1 \,.\, a_2 \,.\, a_3 \,.\, \,\cdots\, \,.\,a_k and can be one of two types:

  1. Add an item a1 . a2 . a3 . ⋯ . ak . 1a_1 \,.\, a_2 \,.\, a_3 \,.\, \cdots \,.\, a_k \,.\, 1 (starting a list of a deeper level), or
  2. Add an item a1 . a2 . a3 . ⋯ . (ak+1)a_1 \,.\, a_2 \,.\, a_3 \,.\, \cdots \,.\, (a_k + 1) (continuing the current level).

Operation can only be applied if the list does not contain two identical items afterwards. And also, if we consider every item as a sequence of numbers, then the sequence of items should always remain increasing in lexicographical order. Examples of valid and invalid lists that are shown in the picture can found in the "Notes" section.

When William decided to save a Word document with the list of his errands he accidentally hit a completely different keyboard shortcut from the "Ctrl-S" he wanted to hit. It's not known exactly what shortcut he pressed but after triggering it all items in the list were replaced by a single number: the last number originally written in the item number.

William wants you to help him restore a fitting original nested list.

威廉是一位热衷于提前规划的人。正因如此,他每天早晨的例行事务始于创建一个嵌套式待办事项列表。

一个合法的嵌套列表,是指从仅含一个元素 "1" 的列表出发,通过执行若干次操作所能生成的任意列表。每次操作均在现有某一项 a1 . a2 . a3 .  ⋯  . aka_1 \,.\, a_2 \,.\, a_3 \,.\, \,\cdots\, \,.\,a_k 之后、新起一行插入一个新项,且该操作只能是以下两种类型之一:

  1. 插入一项 a1 . a2 . a3 . ⋯ . ak . 1a_1 \,.\, a_2 \,.\, a_3 \,.\, \cdots \,.\, a_k \,.\, 1(开启一个更深层级的子列表),或
  2. 插入一项 a1 . a2 . a3 . ⋯ . (ak+1)a_1 \,.\, a_2 \,.\, a_3 \,.\, \cdots \,.\, (a_k + 1)(在同一层级继续编号)。

每次操作仅在满足以下两个条件时才允许执行:

  • 操作后列表中不出现两个完全相同的项;
  • 若将每一项视作一个数字序列,则所有项所构成的序列必须始终保持字典序严格递增。
    图中所示的合法与非法列表示例详见“注释”部分。

当威廉决定将这份待办事项列表保存为 Word 文档时,他本想按下 Ctrl-S,却不慎误触了另一个完全不同的键盘快捷键。目前尚不清楚他具体按下了哪个快捷键,但触发该快捷键后,列表中所有项均被替换为一个单独的数字:即该项原始编号中最后一位数字。

威廉希望你能帮他还原出一个符合要求的原始嵌套列表。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤101 \le t \le 10). Description of the test cases follows.

The first line of each test case contains a single integer nn (1≤n≤1031 \le n \le 10^3), which is the number of lines in the list.

Each of the next nn lines contains a single integer aia_i (1≤ai≤n1 \le a_i \le n), which is what remains of William's nested list.

It is guaranteed that in each test case at least one fitting list exists.

It is guaranteed that the sum of values nn across all test cases does not exceed 10310^3.

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤101 \le t \le 10)。随后是各测试用例的描述。

每个测试用例的第一行包含一个整数 nn(1≤n≤1031 \le n \le 10^3),表示列表中的行数。

接下来的 nn 行中,每行包含一个整数 aia_i(1≤ai≤n1 \le a_i \le n),即 William 的嵌套列表经简化后所剩余的内容。

保证在每个测试用例中,至少存在一个符合条件的列表。

保证所有测试用例的 nn 值之和不超过 10310^3。

输出格式

For each test case output nn lines which represent a valid nested list, which could become the data provided to you by William.

If there are multiple answers, print any.

对于每个测试用例,输出 nn 行,表示一个有效的嵌套列表,该列表可作为 William 提供给你的数据。

若存在多个答案,输出任意一个即可。

输入输出样例

  • 输入#1

    2
    4
    1
    1
    2
    3
    9
    1
    1
    1
    2
    2
    1
    2
    1
    2

    输出#1

    1
    1.1
    1.2
    1.3
    1
    1.1
    1.1.1
    1.1.2
    1.2
    1.2.1
    2
    2.1
    2.2

说明/提示

In the second example test case one example of a fitting list is:

1

1.1

1.1.1

1.1.2

1.2

1.2.1

2

2.1

2.2

This list can be produced by using the sequence of operations shown below:

  1. Original list with a single item 11.
  2. Insert item 22 by using the insertion operation of the second type after item 11.
  3. Insert item 1.11.1 by using the insertion operation of the first type after item 11.
  4. Insert item 1.21.2 by using the insertion operation of the second type after item 1.11.1.
  5. Insert item 1.1.11.1.1 by using the insertion operation of the first type after item 1.11.1.
  6. Insert item 1.1.21.1.2 by using the insertion operation of the second type after item 1.1.11.1.1.
  7. Insert item 1.2.11.2.1 by using the insertion operation of the first type after item 1.21.2.
  8. Insert item 2.12.1 by using the insertion operation of the first type after item 22.
  9. Insert item 2.22.2 by using the insertion operation of the second type after item 2.12.1.

在第二个样例测试用例中,一个符合要求的列表示例如下:

1

1.1

1.1.1

1.1.2

1.2

1.2.1

2

2.1

2.2

该列表可通过执行下图所示的操作序列得到:

  1. 初始列表仅含一项 11。
  2. 使用第二类插入操作,在项 11 之后插入项 22。
  3. 使用第一类插入操作,在项 11 之后插入项 1.11.1。
  4. 使用第二类插入操作,在项 1.11.1 之后插入项 1.21.2。
  5. 使用第一类插入操作,在项 1.11.1 之后插入项 1.1.11.1.1。
  6. 使用第二类插入操作,在项 1.1.11.1.1 之后插入项 1.1.21.1.2。
  7. 使用第一类插入操作,在项 1.21.2 之后插入项 1.2.11.2.1。
  8. 使用第一类插入操作,在项 22 之后插入项 2.12.1。
  9. 使用第二类插入操作,在项 2.12.1 之后插入项 2.22.2。

输入解题思路,AI测评打分。不知道怎么写?

首页