PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#FT0000040. Bộ sưu tập phim (Movie Collection)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Bộ sưu tập phim (Movie Collection)

Movie Collection

Source: Kattis

Version: Phuoc Hung OJ Extended

Problem Statement

A collection contains mm numbered movie boxes stacked vertically. Initially their labels, from top to bottom, are 1,2,…,m1,2,\ldots,m, with one box per label.

There are rr requests. At request ii, locate box aia_i, 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 m,rm,r, the number of movie boxes and requests.
  • Line 2: rr integers a1,a2,…,ara_1,a_2,\ldots,a_r specifying the requested box at each step.

Output

Print rr integers on one line, one per request: the number of boxes above aia_i before it is moved.

Subtasks

Subtask 1 (20 points):

  • 1≤m≤201\le m\le 20; 1≤r≤201\le r\le 20; 1≤ai≤m1\le a_i\le m for all 1≤i≤r1\le i\le r; labels 1,2,…,m1,2,\ldots,m occur exactly once initially.

Subtask 2 (30 points):

  • 1≤m≤20001\le m\le 2000; 1≤r≤20001\le r\le 2000; 1≤ai≤m1\le a_i\le m for all 1≤i≤r1\le i\le r; labels 1,2,…,m1,2,\ldots,m occur exactly once initially.

Subtask 3 (50 points):

  • 1≤m≤1000001\le m\le 100000; 1≤r≤1000001\le r\le 100000; 1≤ai≤m1\le a_i\le m for all 1≤i≤r1\le i\le r; labels 1,2,…,m1,2,\ldots,m occur exactly once initially.

Examples

Examples 1

Input

3 3
3 1 1

Output

2 1 0

Explanation

Initially the stack is [1,2,3][1,2,3]. Box 33 has 22 boxes above it, then moves to the front: [3,1,2][3,1,2]. Box 11 now has 11 box above it, then moves to the front: [1,3,2][1,3,2]. The final request for box 11 finds it on top, giving 00.

Examples 2

Input

5 3
4 4 5

Output

3 0 4

Explanation

Start with [1,2,3,4,5][1,2,3,4,5]. Box 44 has 33 boxes above it and moves to the front, giving [4,1,2,3,5][4,1,2,3,5]. Requesting 44 again returns 00. Box 55 remains at the bottom and has 44 boxes above it.