CF1870C.Colorful Table

普及-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are given two integers nn and kk. You are also given an array of integers a1,a2,…,ana_1, a_2, \ldots, a_n of size nn. It is known that for all 1≤i≤n1 \leq i \leq n, 1≤ai≤k1 \leq a_i \leq k.

Define a two-dimensional array bb of size n×nn \times n as follows: bi,j=min⁡(ai,aj)b_{i, j} = \min(a_i, a_j). Represent array bb as a square, where the upper left cell is b1,1b_{1, 1}, rows are numbered from top to bottom from 11 to nn, and columns are numbered from left to right from 11 to nn. Let the color of a cell be the number written in it (for a cell with coordinates (i,j)(i, j), this is bi,jb_{i, j}).

For each color from 11 to kk, find the smallest rectangle in the array bb containing all cells of this color. Output the sum of width and height of this rectangle.

给你两个整数 nn 和 kk。同时给你一个长度为 nn 的整数数组 a1,a2,…,ana_1, a_2, \ldots, a_n。已知对所有 1≤i≤n1 \leq i \leq n,均有 1≤ai≤k1 \leq a_i \leq k。

定义一个大小为 n×nn \times n 的二维数组 bb 如下:bi,j=min⁡(ai,aj)b_{i, j} = \min(a_i, a_j)。将数组 bb 表示为一个方阵,其中左上角单元格为 b1,1b_{1, 1},行号从上到下依次为 11 至 nn,列号从左到右依次为 11 至 nn。每个单元格的颜色即为其所填数字(对于坐标为 (i,j)(i, j) 的单元格,其颜色为 bi,jb_{i, j})。

对每种颜色 11 至 kk,找出包含该颜色所有单元格的最小矩形。输出该矩形的宽度与高度之和。

输入格式

The first line contains a single integer tt (1≤t≤1041 \leq t \leq 10^4) — the number of test cases. Then follows the description of the test cases.

The first line of each test case contains two integers nn and kk (1≤n,k≤1051 \leq n, k \leq 10^5) — the size of array aa and the number of colors.

The second line of each test case contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (1≤ai≤k1 \leq a_i \leq k) — the array aa.

It is guaranteed that the sum of the values of nn and kk over all test cases does not exceed 10510^5.

第一行包含一个整数 tt(1≤t≤1041 \leq t \leq 10^4)——测试用例的数量。随后是各测试用例的描述。

每个测试用例的第一行包含两个整数 nn 和 kk(1≤n,k≤1051 \leq n, k \leq 10^5)——数组 aa 的大小和颜色数量。

每个测试用例的第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(1≤ai≤k1 \leq a_i \leq k)——数组 aa。

保证所有测试用例中 nn 与 kk 的总和不超过 10510^5。

输出格式

For each test case, output kk numbers: the sums of width and height of the smallest rectangle containing all cells of a color, for each color from 11 to kk.

对于每个测试用例,输出 kk 个数字:对颜色 11 到 kk 中的每种颜色,输出包含该颜色所有格子的最小矩形的宽度与高度之和。

输入输出样例

  • 输入#1

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

    输出#1

    4 
    4 2 
    0 6 6 2 0 
    8 6 
    10 6 2

说明/提示

In the first test case, the entire array bb consists of color 11, so the smallest rectangle for color 11 has a size of 2×22 \times 2, and the sum of its sides is 44.

In the second test case, the array bb looks like this:

1

1

1

2

One of the corner cells has color 22, and the other three cells have color 11. Therefore, the smallest rectangle for color 11 has a size of 2×22 \times 2, and for color 22 it is 1×11 \times 1.

In the last test case, the array bb looks like this:

1

1

1

1

1

1

2

2

2

1

1

2

3

2

1

1

2

2

2

1

1

1

1

1

1

在第一个测试用例中,整个数组 bb 仅包含颜色 11,因此颜色 11 的最小矩形大小为 2×22 \times 2,其边长之和为 44。

在第二个测试用例中,数组 bb 如下所示:

1

1

1

2

其中一个角上的格子颜色为 22,其余三个格子颜色均为 11。因此,颜色 11 的最小矩形大小为 2×22 \times 2,而颜色 22 的最小矩形大小为 1×11 \times 1。

在最后一个测试用例中,数组 bb 如下所示:

1

1

1

1

1

1

2

2

2

1

1

2

3

2

1

1

2

2

2

1

1

1

1

1

1

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

首页