Welcome to ZOJ Problem Sets Information Select Problem Runs Ranklist ZOJ Problem Set - 4117
BaoBao Loves Reading

Time Limit: 1 Second      Memory Limit: 65536 KB

BaoBao is a good student who loves reading, but compared with his huge bookshelf containing lots and lots of books, his reading desk, which can only hold at most $k$ books, is surprisingly small.

Today BaoBao decides to read some books for $n$ minutes by the desk. According to his reading plan, during the $i$-th minute, he is scheduled to read book $a_i$. The reading desk is initially empty and all the books are initially on the shelf. If the book BaoBao decides to read is not on the desk, BaoBao will have to fetch it from the shelf. Also, if the desk is full and BaoBao has to fetch another book from the shelf, he will have to put one book back from the desk to the shelf before fetching the new book.

Tired of deciding which book to put back, BaoBao searches the Internet and discovers an algorithm called the Least Recently Used (LRU) algorithm. According to the algorithm, when BaoBao has to put a book back from the desk to the shelf, he should put back the least recently read book.

For example, let's consider the reading plan {4, 3, 4, 2, 3, 1, 4} and assume that the capacity of the desk is 3. The following table explains what BaoBao should do according to the LRU algorithm. Note that in the following table, we use a pair of integer $(a, b)$ to represent a book, where $a$ is the index of the book, and $b$ is the last time when this book is read.

Minute Books on the Desk
Before This Minute
BaoBao's Action
1 {} Fetch book 4 from the shelf
2 {(4, 1)} Fetch book 3 from the shelf
3 {(4, 1), (3, 2)} Do nothing as book 4 is already on the desk
4 {(4, 3), (3, 2)} Fetch book 2 from the shelf
5 {(4, 3), (3, 2), (2, 4)} Do nothing as book 3 is already on the desk
6 {(4, 3), (3, 5), (2, 4)} Put book 4 back to the shelf as its the least recently read book,
and fetch book 1 from the shelf
7 {(3, 5), (2, 4), (1, 6)} Put book 2 back to the shelf as its the least recently read book,
and fetch book 4 from the shelf

Given the reading plan, what's the number of times BaoBao fetches a book from the shelf if the value of $k$ (the capacity of the desk) ranges from 1 to $n$ (both inclusive)?

#### Input

There are multiple test cases. The first line of the input contains an integer $T$, indicating the number of test cases. For each test case:

The first line contains an integer $n$ ($1 \le n \le 10^5$), indicating the length of the reading plan.

The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le n$), indicating the indices of the books to read.

It's guaranteed that the sum of $n$ of all test cases will not exceed $10^6$.

#### Output

For each test case output one line containing $n$ integers $f_1, f_2, \dots, f_n$ separated by a space, where $f_i$ indicates the number of times BaoBao fetches a book from the shelf when the capacity of the desk is $i$.

Please, DO NOT output extra spaces at the end of each line, or your solution may be considered incorrect!

#### Sample Input

1
7
4 3 4 2 3 1 4


#### Sample Output

7 6 5 4 4 4 4


Author: WANG, Yucheng
Source: The 10th Shandong Provincial Collegiate Programming Contest
Submit    Status