atcoder#AGC036B. [AGC036B] Do Not Duplicate
[AGC036B] Do Not Duplicate
Score : points
Problem Statement
We have a sequence of integers: . Its elements are represented by another sequence of integers: . For each pair (), holds.
Snuke has an integer sequence , which is initially empty. For each , in this order, he will perform the following operation:
- If does not contain : add to the end of .
- If does contain : repeatedly delete the element at the end of until no longer contains . Note that, in this case, we do not add to the end of .
Find the elements of after Snuke finished the operations.
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the elements of after Snuke finished the operations, in order from beginning to end, with spaces in between.
3 2
1 2 3
2 3
In this case, . We will perform the operations as follows:
- : does not contain , so we add to the end of , resulting in .
- : does not contain , so we add to the end of , resulting in .
- : does not contain , so we add to the end of , resulting in .
- : does contain , so we repeatedly delete the element at the end of as long as contains , which causes the following changes to : .
- : does not contain , so we add to the end of , resulting in .
- : does not contain , so we add to the end of , resulting in .
5 10
1 2 3 2 3
3
6 1000000000000
1 1 2 2 3 3
may be empty in the end.
11 97
3 1 4 1 5 9 2 6 5 3 5
9 2 6