In the adaptive search systems of Prime City, the Engineer uses a self-organizing list with the move-to-front heuristic. When an element is found, it is moved to the front of the list. Over time, frequently searched elements accumulate at the front, reducing average search time. "The move-to-front heuristic is simple but powerful," the Engineer says. "After each successful search, move the found element to position 0. This adapts the list to the access pattern." Given an initial list of N distinct integers and a sequence of K search queries, simulate the move-to-front heuristic. For each query, output the position (0-based) of the found element in the current list, then move it to the front. If the element is not found, output -1 and do not modify the list. Constraints: 1 <= N <= 10^5, 1 <= K <= 10^5, all elements are distinct Input: 5 1 2 3 4 5 3 3 1 3 Output: 2 2 0 Input: 3 10 20 30 2 20 20 Output: 1 0
Constraints:
1 <= N, K <= 10^5, all elements distinct
Tags:
