Movie Collection
InterviewTime limit1sMemory limit256 MB
Given a stack of DVDs and a sequence of watched movie numbers, output for each watch how many DVDs sat above it before moving it to the top.
- Level
Medium4 of 10
- Topics
- Array, Simulation, Implementation
- Solved
- No attempts yet
Problem
Sanggeun is a movie DVD collector. He keeps his DVDs stacked in a single pile.
Whenever he wants to watch a movie, he locates its DVD and carefully pulls it out without toppling the pile. After finishing the movie, he places that DVD back on top of the pile.
Because Sanggeun owns so many DVDs, locating a movie takes a long time. The position of a DVD is easy to determine once you know how many DVDs are stacked on top of it. Each movie is identified by the number printed on its cover.
Write a program that, every time Sanggeun watches a movie, reports how many DVDs were on top of that DVD.
Input
The first line contains the number of test cases, which is at most .
The first line of each test case contains , the number of movies Sanggeun owns, and , the number of movies he will watch. ()
The second line contains the movie numbers, in the order he watches them.
Movies are numbered from to . Initially the DVDs are stacked in increasing order of their numbers, and the DVD on the very top has number .
Output
For each test case, print integers on a single line, separated by spaces.
The -th number is the number of DVDs that were on top of the DVD when the -th movie is watched. Each time Sanggeun watches a movie, he puts that DVD back on top of the pile.