CF1238B.Kill 'Em All

普及-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Ivan plays an old action game called Heretic. He's stuck on one of the final levels of this game, so he needs some help with killing the monsters.

The main part of the level is a large corridor (so large and narrow that it can be represented as an infinite coordinate line). The corridor is divided into two parts; let's assume that the point x=0x = 0 is where these parts meet.

The right part of the corridor is filled with nn monsters — for each monster, its initial coordinate xix_i is given (and since all monsters are in the right part, every xix_i is positive).

The left part of the corridor is filled with crusher traps. If some monster enters the left part of the corridor or the origin (so, its current coordinate becomes less than or equal to 00), it gets instantly killed by a trap.

The main weapon Ivan uses to kill the monsters is the Phoenix Rod. It can launch a missile that explodes upon impact, obliterating every monster caught in the explosion and throwing all other monsters away from the epicenter. Formally, suppose that Ivan launches a missile so that it explodes in the point cc. Then every monster is either killed by explosion or pushed away. Let some monster's current coordinate be yy, then:

  • if c=yc = y, then the monster is killed;
  • if y<cy \lt c, then the monster is pushed rr units to the left, so its current coordinate becomes y−ry - r;
  • if y>cy \gt c, then the monster is pushed rr units to the right, so its current coordinate becomes y+ry + r.

Ivan is going to kill the monsters as follows: choose some integer point dd and launch a missile into that point, then wait until it explodes and all the monsters which are pushed to the left part of the corridor are killed by crusher traps, then, if at least one monster is still alive, choose another integer point (probably the one that was already used) and launch a missile there, and so on.

What is the minimum number of missiles Ivan has to launch in order to kill all of the monsters? You may assume that every time Ivan fires the Phoenix Rod, he chooses the impact point optimally.

You have to answer qq independent queries.

伊万正在玩一款名为《异教徒》(Heretic)的老式动作游戏。他卡在了该游戏的某个最终关卡,因此需要一些帮助来消灭怪物。

该关卡的主要部分是一条巨大的走廊(其尺度之大、宽度之窄,可将其建模为一条无限长的数轴)。走廊被划分为左右两部分;我们设分界点为 x=0x = 0。

走廊的右半部分(即 x>0x > 0 区域)分布着 nn 只怪物——每只怪物的初始坐标 xix_i 已知(由于所有怪物均位于右半部分,故每个 xix_i 均为正数)。

走廊的左半部分(即 x≤0x \leq 0 区域)布满了压碎陷阱。若某只怪物进入左半部分或到达原点(即其当前坐标 ≤0\leq 0),它将立即被陷阱杀死。

伊万用来消灭怪物的主要武器是“凤凰魔杖”(Phoenix Rod)。该武器可发射一枚导弹,命中后发生爆炸:爆炸会瞬间消灭所有处于爆心位置的怪物,并将其他所有怪物沿远离爆心的方向弹开。形式化地,假设伊万向坐标 cc 发射一枚导弹,则每只怪物将按如下规则处理:设某只怪物当前坐标为 yy,则:

  • 若 c=yc = y,则该怪物被爆炸直接消灭;
  • 若 y<cy < c,则该怪物被向左弹开 rr 个单位,其新坐标变为 y−ry - r;
  • 若 y>cy > c,则该怪物被向右弹开 rr 个单位,其新坐标变为 y+ry + r。

伊万消灭怪物的过程如下:首先选择某个整数坐标 dd 并向该点发射一枚导弹;待导弹爆炸、所有被向左弹入走廊左半部分(即坐标 ≤0\leq 0)的怪物被陷阱杀死后,若仍有至少一只怪物存活,则再次选择一个整数坐标(可以与之前使用过的坐标相同)并发射一枚导弹;如此反复,直至所有怪物全部死亡。

问:伊万最少需要发射多少枚导弹才能消灭所有怪物?你可以假设:每次伊万使用凤凰魔杖时,都会以最优方式选择爆炸点。

你需要回答 qq 个相互独立的查询。

输入格式

The first line contains one integer qq (1≤q≤1051 \le q \le 10^5) — the number of queries.

The first line of each query contains two integers nn and rr (1≤n,r≤1051 \le n, r \le 10^5) — the number of enemies and the distance that the enemies are thrown away from the epicenter of the explosion.

The second line of each query contains nn integers xix_i (1≤xi≤1051 \le x_i \le 10^5) — the initial positions of the monsters.

It is guaranteed that sum of all nn over all queries does not exceed 10510^5.

第一行包含一个整数 qq(1≤q≤1051 \le q \le 10^5)—— 查询次数。

每次查询的第一行包含两个整数 nn 和 rr(1≤n,r≤1051 \le n, r \le 10^5)—— 敌人的数量,以及敌人被爆炸中心击退的距离。

每次查询的第二行包含 nn 个整数 xix_i(1≤xi≤1051 \le x_i \le 10^5)—— 怪物的初始位置。

保证所有查询中 nn 的总和不超过 10510^5。

输出格式

For each query print one integer — the minimum number of shots from the Phoenix Rod required to kill all monsters.

对于每个查询,输出一个整数——使用凤凰魔杖消灭所有怪物所需的最少射击次数。

输入输出样例

  • 输入#1

    2
    3 2
    1 3 5
    4 1
    5 2 3 5

    输出#1

    2
    2

说明/提示

In the first test case, Ivan acts as follows:

  • choose the point 33, the first monster dies from a crusher trap at the point −1-1, the second monster dies from the explosion, the third monster is pushed to the point 77;
  • choose the point 77, the third monster dies from the explosion.

In the second test case, Ivan acts as follows:

  • choose the point 55, the first and fourth monsters die from the explosion, the second monster is pushed to the point 11, the third monster is pushed to the point 22;
  • choose the point 22, the first monster dies from a crusher trap at the point 00, the second monster dies from the explosion.

在第一个测试用例中,Ivan 的操作如下:

  • 选择位置 33,第一只怪物在位置 −1-1 处被压路陷阱消灭,第二只怪物被爆炸消灭,第三只怪物被推至位置 77;
  • 选择位置 77,第三只怪物被爆炸消灭。

在第二个测试用例中,Ivan 的操作如下:

  • 选择位置 55,第一只和第四只怪物被爆炸消灭,第二只怪物被推至位置 11,第三只怪物被推至位置 22;
  • 选择位置 22,第一只怪物在位置 00 处被压路陷阱消灭,第二只怪物被爆炸消灭。

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

首页