#K72392. Recent Unique Integers

    ID: 33743 Type: Default 1000ms 256MiB

Recent Unique Integers

Recent Unique Integers

You are given a data stream of integers and a capacity k. Your task is to implement a data structure that maintains the most recent k unique integers from the stream.

When processing an operation of the form add x, if x is already present in the data structure, ignore it. If x is not present and the data structure already contains k elements, remove the oldest element before adding x. For an operation get, output the current list of stored integers in the order they were added (from oldest to newest). Note that if the list is empty, simply output an empty line.

The capacity condition can be formulated as: $$|\text{RecentUnique}| \leq k.$$

inputFormat

The first line of input contains two integers k and n, where k is the maximum capacity of the data structure and n is the number of operations.

The following n lines each contain an operation, which is either:

  • add x — add the integer x to the data structure, or
  • get — output the current list of unique integers

For a get operation, if the data structure is empty, output an empty line.

outputFormat

For every get operation from the input, print a single line containing the current list of unique integers stored in the data structure. The integers should be separated by a single space. If the list is empty, output an empty line.

## sample
3 7
add 1
add 2
get
add 3
get
add 2
add 4
get
1 2

1 2 3 2 3 4

</p>