CF2259G.Index Removal

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

An array b1,b2,…,bmb_1, b_2, \ldots, b_m is good if, for each ii (1≤i<m)(1 \leq i \lt m), bi+1≥bib_{i+1} \geq b_i and bi+1−bi≤kb_{i+1} - b_i \leq k. An array of length 11 is always good.

You are given an initially good array a1,a2,…,ana_1, a_2, \ldots, a_n. Solve the following problem for each ii (1≤i≤n)(1 \leq i \leq n) independently:

  • The ii-th element of aa is removed, making a=[a1,a2,…,ai−1,ai+1,…,an]a = [a_1, a_2, \ldots, a_{i-1}, a_{i+1}, \ldots, a_n]. In one operation, you are able to subtract 11 from any element of aa. What is the minimum number of operations required to make aa good again?

数组 b1,b2,…,bmb_1, b_2, \ldots, b_m 被称为好数组,当且仅当对每个 ii(1≤i<m1 \leq i \lt m),均满足 bi+1≥bib_{i+1} \geq b_i 且 bi+1−bi≤kb_{i+1} - b_i \leq k。长度为 11 的数组恒为好数组。

给定一个初始的好数组 a1,a2,…,ana_1, a_2, \ldots, a_n。对每个 ii(1≤i≤n1 \leq i \leq n),独立求解如下问题:

  • 删除 aa 的第 ii 个元素,得到 a=[a1,a2,…,ai−1,ai+1,…,an]a = [a_1, a_2, \ldots, a_{i-1}, a_{i+1}, \ldots, a_n]。每次操作允许将 aa 中任意一个元素减 11。问:使 aa 再次成为好数组所需的最少操作次数是多少?

输入格式

The first line of each input contains tt (1≤t≤1041 \leq t \leq 10^4) — the number of test cases.

The first line of each test case contains two integers nn and kk (2≤n≤2⋅105,1≤k≤1092 \leq n \leq 2 \cdot 10^5, 1 \leq k \leq 10^9).

The second line of each test case contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (1≤ai≤1091 \leq a_i \leq 10^9). It is guaranteed that aa is initially good.

It is guaranteed that the sum of nn over all test cases does not exceed 2⋅1052 \cdot 10^5.

每组输入的第一行包含一个整数 tt(1≤t≤1041 \leq t \leq 10^4),表示测试用例的数量。

每个测试用例的第一行包含两个整数 nn 和 kk(2≤n≤2⋅1052 \leq n \leq 2 \cdot 10^5,1≤k≤1091 \leq k \leq 10^9)。

每个测试用例的第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(1≤ai≤1091 \leq a_i \leq 10^9)。保证初始数组 aa 是“好的”。

保证所有测试用例的 nn 之和不超过 2⋅1052 \cdot 10^5。

输出格式

For each test case, output nn space separated integers on a single line: the ii-th integer denoting the solution to the problem for the ii-th index.

对于每个测试用例,在一行中输出 nn 个以空格分隔的整数:第 ii 个整数表示该问题在第 ii 个下标处的解。

输入输出样例

  • 输入#1

    7
    4 2
    1 2 4 5
    4 1
    1 2 3 4
    5 7
    1 8 9 16 20
    5 1000000000
    1 6 7 67 6767
    6 1
    1 1 2 2 3 4
    4 1
    1 2 3 3
    4 2
    1 2 4 6

    输出#1

    0 1 1 0 
    0 2 1 0 
    0 2 1 4 0 
    0 0 0 0 0 
    0 0 0 0 1 0 
    0 1 0 0 
    0 2 2 0

说明/提示

In the first test case:

  • i=1i = 1, a=[2,4,5]a = [2, 4, 5]. Since aa is still good, we do not need to perform any operations.
  • i=2i = 2, a=[1,4,5]a = [1, 4, 5]. If we perform the operation once on the 22nd element, a=[1,3,5]a = [1, 3, 5], which is a good array.
  • i=3i = 3, a=[1,2,5]a = [1, 2, 5]. If we perform the operation once on the 33rd element, a=[1,2,4]a = [1, 2, 4], which is a good array.
  • i=4i = 4, a=[1,2,4]a = [1, 2, 4]. Since aa is still good, we do not need to perform any operations.

In the fourth test case, aa will remain good no matter what element we remove, so the answer for each index is 00.

在第一个测试用例中:

  • i=1i = 1,a=[2,4,5]a = [2, 4, 5]。由于 aa 仍是好数组,因此无需执行任何操作。
  • i=2i = 2,a=[1,4,5]a = [1, 4, 5]。若对第 22 个元素执行一次操作,则 a=[1,3,5]a = [1, 3, 5],这是一个好数组。
  • i=3i = 3,a=[1,2,5]a = [1, 2, 5]。若对第 33 个元素执行一次操作,则 a=[1,2,4]a = [1, 2, 4],这是一个好数组。
  • i=4i = 4,a=[1,2,4]a = [1, 2, 4]。由于 aa 仍是好数组,因此无需执行任何操作。

在第四个测试用例中,无论移除哪个元素,aa 始终保持为好数组,因此每个下标对应的答案均为 00。

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

首页