SAM - Toy Cars

题意翻译

Jasio 是一个只有三岁的小男孩,他喜欢玩玩具车。他有 $n$ 辆玩具车被保存在书架上。 架子上的玩具车 Jasio 拿不到,但地板上的他可以拿到。Jasio 的母亲会帮 Jasio 拿架子上的玩具车到地板上。 地板最多只能放 $k$ 辆玩具车。 当地板已经放了 $k$ 辆玩具车时,Jasio 的母亲都会从地板上先拿走一个玩具车放回书架,再拿来 Jasio 想要的玩具车。 现在 Jasio 一共想依次玩 $p$ 个玩具车,问 Jasio 的母亲最少需要拿几次玩具车。(只算拿下来的,不算拿上去的) **【输入格式】** 第一行一个整数 $t$,表示有 $t$ 组数据。 接下来一行有三个整数 $n,k$ 和 $p$。 接下来 $p$ 行,每一行有且仅有一个整数 $a_i$,表示 Jasio 想玩的玩具玩家车编号。 **【输出格式】** 输出一行一个整数,表示最少 Jasio 的母亲最少需要拿玩家车的次数。 **【数据范围】** 对于 $100\%$ 的数据:$1\le t\le 16$,$1\le k\le n\le 10^5$,$1\le p\le 5\times 10^5$,$1\le a_i\le n$。 感谢 @Utilokasteinn 提供的翻译。

题目描述

Jasio is a little boy - he is only three years old and enjoys playing with toy cars very much. Jasio has n different cars. They are kept on a shelf so high, that Jasio cannot reach it by himself. As there is little space in his room, at no moment may there be more than k toy cars on the floor. Jasio plays with one of the cars on the floor. Jasio's mother remains in the room with her son all the time. When Jasio wants to play with another car that is on the floor, he reaches it by himself. But when the toy is on the shelf, his mummy has to hand it to him. When she gives Jasio one car, she can at the same time pick any car from the floor and put it back on the shelf (so that there remains sufficient space on the floor). The mother knows her child very well and therefore can predict perfectly which cars Jasio will want to play with. Having this knowledge, she wants to minimize the number of times she has to hand Jasio a toy from the shelf. Keeping that in mind, she has to put the toys off on the shelf extremely thoughtfully. **Task** Write a programme that: **1.**reads from the standard input the sequence of toy cars in order in which Jasio will want to play with them, **2.**calculates the minimal number of times the mother has to pick cars from the shelf, **3.**writes the result to the standard output.

输入输出格式

输入格式


In the first line of the standard input is H- the number of test case (H <= 16). For each test case follow contains some lines, start with three integers: n, k, p (1 <= k <= n <= 100000, 1 <= p <= 500000), separated by single spaces. These denote respectively: the total number of cars, the number of cars that can remain on the floor at once and the length of the sequence of cars which Jasio will want to play with. Each of the following p lines contains one integer. These integers are the numbers of cars Jasio will want to play with (the cars are numbered from 1 to n ).

输出格式


For each test case, you should write only one integer - the minimal number of times his mother has to pick a car from the shelf.

输入输出样例

输入样例 #1

1
3 2 7
1
2
3
1
3
1
2

输出样例 #1

4