QOJ.ac

QOJ

時間限制: 1 s 記憶體限制: 32 MB 總分: 100

#11858. 玩具车

统计

Johnny 是个小男孩,他今年才三岁,非常喜欢玩玩具车。Johnny 有 $n$ 辆不同的玩具车。这些车放在一个很高的架子上,Johnny 自己够不着。由于他的房间空间有限,地板上任何时候最多只能放 $k$ 辆玩具车。

Johnny 在地板上玩其中的一辆车。Johnny 的妈妈一直陪着他。当 Johnny 想玩地板上已有的另一辆车时,他可以自己拿到。但如果玩具在架子上,妈妈就必须递给他。当妈妈递给 Johnny 一辆车时,她可以同时从地板上拿走任意一辆车放回架子上(以便地板上有足够的空间)。

妈妈非常了解她的孩子,因此可以准确预测 Johnny 接下来想玩哪些车。有了这些信息,她希望最小化她从架子上拿玩具给 Johnny 的次数。考虑到这一点,她必须非常谨慎地决定把哪些玩具放回架子上。

请编写一个程序:

  • 从标准输入读取 Johnny 想玩玩具车的顺序序列;
  • 计算妈妈从架子上拿取玩具的最小次数;
  • 将结果写入标准输出。

输入格式

标准输入的第一行包含三个整数:$n$、$k$、$p$($1 \le k \le n \le 100\,000$,$1 \le p \le 500\,000$),用空格分隔。它们分别表示:玩具车的总数、地板上同时最多能放的玩具车数量,以及 Johnny 想玩玩具车的序列长度。接下来的 $p$ 行,每行包含一个整数。这些整数代表 Johnny 想玩的玩具车编号(玩具车编号从 $1$ 到 $n$)。

输出格式

在标准输出的第一行(也是唯一一行)中,输出一个整数,表示妈妈从架子上拿取玩具的最小次数。

样例

输入 1

3 2 7
1
2
3
1
3
1
2

输出 1

4

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.