#FT0000040. Bộ sưu tập phim (Movie Collection)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Bộ sưu tập phim (Movie Collection)
Movie Collection
Source: Kattis
Version: Phuoc Hung OJ Extended
Problem Statement
A collection contains numbered movie boxes stacked vertically. Initially their labels, from top to bottom, are , with one box per label.
There are requests. At request , locate box , record the number of boxes currently above it, then move that box to the very top. All other boxes retain their relative order.
Report the number of boxes above the requested box just before each move. A movie may be requested repeatedly; later requests use the updated stack.
Input
- Line 1: integers , the number of movie boxes and requests.
- Line 2: integers specifying the requested box at each step.
Output
Print integers on one line, one per request: the number of boxes above before it is moved.
Subtasks
Subtask 1 (20 points):
- ; ; for all ; labels occur exactly once initially.
Subtask 2 (30 points):
- ; ; for all ; labels occur exactly once initially.
Subtask 3 (50 points):
- ; ; for all ; labels occur exactly once initially.
Examples
Examples 1
Input
3 3
3 1 1
Output
2 1 0
Explanation
Initially the stack is . Box has boxes above it, then moves to the front: . Box now has box above it, then moves to the front: . The final request for box finds it on top, giving .
Examples 2
Input
5 3
4 4 5
Output
3 0 4
Explanation
Start with . Box has boxes above it and moves to the front, giving . Requesting again returns . Box remains at the bottom and has boxes above it.