CF1190A.Tokitsukaze and Discard Items

普及/提高-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Recently, Tokitsukaze found an interesting game. Tokitsukaze had nn items at the beginning of this game. However, she thought there were too many items, so now she wants to discard mm (1≤m≤n1 \le m \le n) special items of them.

These nn items are marked with indices from 11 to nn. In the beginning, the item with index ii is placed on the ii-th position. Items are divided into several pages orderly, such that each page contains exactly kk positions and the last positions on the last page may be left empty.

Tokitsukaze would do the following operation: focus on the first special page that contains at least one special item, and at one time, Tokitsukaze would discard all special items on this page. After an item is discarded or moved, its old position would be empty, and then the item below it, if exists, would move up to this empty position. The movement may bring many items forward and even into previous pages, so Tokitsukaze would keep waiting until all the items stop moving, and then do the operation (i.e. check the special page and discard the special items) repeatedly until there is no item need to be discarded.

Consider the first example from the statement: n=10n=10, m=4m=4, k=5k=5, p=[3,5,7,10]p=[3, 5, 7, 10]. The are two pages. Initially, the first page is special (since it is the first page containing a special item). So Tokitsukaze discards the special items with indices 33 and 55. After, the first page remains to be special. It contains [1,2,4,6,7][1, 2, 4, 6, 7], Tokitsukaze discards the special item with index 77. After, the second page is special (since it is the first page containing a special item). It contains [9,10][9, 10], Tokitsukaze discards the special item with index 1010.

Tokitsukaze wants to know the number of operations she would do in total.

最近,时雨发现了一个有趣的游戏。游戏开始时,时雨拥有 nn 个物品。但她觉得物品数量太多,因此现在她想要丢弃其中 mm 个(1≤m≤n1 \le m \le n)特殊物品。

这 nn 个物品的编号为 11 到 nn。初始时,编号为 ii 的物品位于第 ii 个位置。物品按顺序被划分为若干页,每页恰好包含 kk 个位置,最后一页的末尾位置可能为空。

时雨将执行如下操作:首先定位第一个包含至少一个特殊物品的特殊页,然后一次性丢弃该页上的所有特殊物品。每当一个物品被丢弃或移动后,其原来的位置即变为空;若其下方存在物品,则该物品会向上移动至这个空位。这种移动可能导致大量物品前移,甚至跨页进入前面的页面。因此,时雨会持续等待,直至所有物品停止移动,再重复执行上述操作(即重新检查首个含特殊物品的页并丢弃该页所有特殊物品),直到没有物品需要被丢弃为止。

考虑题面中的第一个示例:n=10n=10,m=4m=4,k=5k=5,p=[3,5,7,10]p=[3, 5, 7, 10]。共分为两页。初始时,第一页是特殊页(因为它是首个包含特殊物品的页)。因此时雨丢弃编号为 33 和 55 的特殊物品。之后,第一页仍为特殊页,其上物品变为 [1,2,4,6,7][1, 2, 4, 6, 7],时雨丢弃编号为 77 的特殊物品。随后,第二页成为特殊页(因为此时它是首个包含特殊物品的页),其上物品为 [9,10][9, 10],时雨丢弃编号为 1010 的特殊物品。

时雨想知道她总共需要执行多少次操作。

输入格式

The first line contains three integers nn, mm and kk (1≤n≤10181 \le n \le 10^{18}, 1≤m≤1051 \le m \le 10^5, 1≤m,k≤n1 \le m, k \le n) — the number of items, the number of special items to be discarded and the number of positions in each page.

The second line contains mm distinct integers p1,p2,…,pmp_1, p_2, \ldots, p_m (1≤p1<p2<…<pm≤n1 \le p_1 \lt p_2 \lt \ldots \lt p_m \le n) — the indices of special items which should be discarded.

第一行包含三个整数 nn、mm 和 kk(1≤n≤10181 \le n \le 10^{18},1≤m≤1051 \le m \le 10^5,1≤m,k≤n1 \le m, k \le n)—— 分别表示物品总数、需丢弃的特殊物品数量以及每页的位置数。

第二行包含 mm 个互不相同的整数 p1,p2,…,pmp_1, p_2, \ldots, p_m(1≤p1<p2<…<pm≤n1 \le p_1 \lt p_2 \lt \ldots \lt p_m \le n)—— 表示需丢弃的特殊物品的索引。

输出格式

Print a single integer — the number of operations that Tokitsukaze would do in total.

输出一个整数——Tokitsukaze 总共执行的操作次数。

输入输出样例

  • 输入#1

    10 4 5
    3 5 7 10

    输出#1

    3
  • 输入#2

    13 4 5
    7 8 9 10

    输出#2

    1

说明/提示

For the first example:

  • In the first operation, Tokitsukaze would focus on the first page [1,2,3,4,5][1, 2, 3, 4, 5] and discard items with indices 33 and 55;
  • In the second operation, Tokitsukaze would focus on the first page [1,2,4,6,7][1, 2, 4, 6, 7] and discard item with index 77;
  • In the third operation, Tokitsukaze would focus on the second page [9,10][9, 10] and discard item with index 1010.

For the second example, Tokitsukaze would focus on the second page [6,7,8,9,10][6, 7, 8, 9, 10] and discard all special items at once.

对于第一个例子:

  • 在第一次操作中,Tokitsukaze 将聚焦于第一页 [1,2,3,4,5][1, 2, 3, 4, 5],并丢弃索引为 33 和 55 的物品;
  • 在第二次操作中,Tokitsukaze 将聚焦于第一页 [1,2,4,6,7][1, 2, 4, 6, 7],并丢弃索引为 77 的物品;
  • 在第三次操作中,Tokitsukaze 将聚焦于第二页 [9,10][9, 10],并丢弃索引为 1010 的物品。

对于第二个例子,Tokitsukaze 将聚焦于第二页 [6,7,8,9,10][6, 7, 8, 9, 10],并一次性丢弃所有特殊物品。

输入解题思路,AI测评打分。不知道怎么写?

首页