1497 MTF逆变换


Submit solution

Points: 100
Time limit: 1.0s
Memory limit: 32M

Problem types
Allowed languages
C, C++, Java, Python

Description

MTF变换其实是可逆的,具体做法是和正变换时一样维持一张表,开始时表中的Value均和Index相等,遇到输入时就在表中找到和输入值相等的索引,输出索引的Value的同时将该Value移动到最前端,如下表所示:

输入 3 2 4 1 5 …

Value 0 1 2 3 4 5 6 7 …

Index 0 1 2 3 4 5 6 7 …

输入3,Index 3对应的Value被输出,同时Value被移动到前端

Value 3 0 1 2 4 5 6 7 …

Index 0 1 2 3 4 5 6 7 …

输入2,Index 2对应的Value被输出,同时Value被移动到前端

Value 1 3 0 2 4 5 6 7 …

Index 0 1 2 3 4 5 6 7 …

输入4, Index 4对应的Value被输出,同时Value被移动到前端

…… 输出 3 1 4 1 5 9 2 6 …

Input

输入约有20000行整数,范围在[0,65535]

Output

依次输出变换的结果,一行一个

Sample

Input

3
2
4
1
5

Output

3
1
4
1
5

Source: 仙剑魔


Comments

There are no comments at the moment.