#P1870C. Colorful Table
Colorful Table
No submission language available for this problem.
Description
You are given two integers and . You are also given an array of integers of size . It is known that for all , .
Define a two-dimensional array of size as follows: . Represent array as a square, where the upper left cell is , rows are numbered from top to bottom from to , and columns are numbered from left to right from to . Let the color of a cell be the number written in it (for a cell with coordinates , this is ).
For each color from to , find the smallest rectangle in the array containing all cells of this color. Output the sum of width and height of this rectangle.
The first line contains a single integer () — the number of test cases. Then follows the description of the test cases.
The first line of each test case contains two integers and () — the size of array and the number of colors.
The second line of each test case contains integers () — the array .
It is guaranteed that the sum of the values of and over all test cases does not exceed .
For each test case, output numbers: the sums of width and height of the smallest rectangle containing all cells of a color, for each color from to .
Input
The first line contains a single integer () — the number of test cases. Then follows the description of the test cases.
The first line of each test case contains two integers and () — the size of array and the number of colors.
The second line of each test case contains integers () — the array .
It is guaranteed that the sum of the values of and over all test cases does not exceed .
Output
For each test case, output numbers: the sums of width and height of the smallest rectangle containing all cells of a color, for each color from to .
Note
In the first test case, the entire array consists of color , so the smallest rectangle for color has a size of , and the sum of its sides is .
In the second test case, the array looks like this:
1 | 1 |
1 | 2 |
One of the corner cells has color , and the other three cells have color . Therefore, the smallest rectangle for color has a size of , and for color it is .
In the last test case, the array 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 |