CF1706B.Making Towers

普及-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You have a sequence of nn colored blocks. The color of the ii-th block is cic_i, an integer between 11 and nn.

You will place the blocks down in sequence on an infinite coordinate grid in the following way.

  1. Initially, you place block 11 at (0,0)(0, 0).
  2. For 2≤i≤n2 \le i \le n, if the (i−1)(i - 1)-th block is placed at position (x,y)(x, y), then the ii-th block can be placed at one of positions (x+1,y)(x + 1, y), (x−1,y)(x - 1, y), (x,y+1)(x, y + 1) (but not at position (x,y−1)(x, y - 1)), as long no previous block was placed at that position.

A tower is formed by ss blocks such that they are placed at positions (x,y),(x,y+1),…,(x,y+s−1)(x, y), (x, y + 1), \ldots, (x, y + s - 1) for some position (x,y)(x, y) and integer ss. The size of the tower is ss, the number of blocks in it. A tower of color rr is a tower such that all blocks in it have the color rr.

For each color rr from 11 to nn, solve the following problem independently:

  • Find the maximum size of a tower of color rr that you can form by placing down the blocks according to the rules.

你有一列 nn 个有颜色的方块。第 ii 个方块的颜色为 cic_i,是一个介于 11 到 nn 之间的整数。

你将按顺序把这些方块放置在一个无限坐标网格上,方式如下:

  1. 最初,将第 11 个方块放在位置 (0,0)(0, 0)。
  2. 对于 2≤i≤n2 \le i \le n,若第 (i−1)(i - 1) 个方块被放置在位置 (x,y)(x, y),则第 ii 个方块可被放置在以下位置之一:(x+1,y)(x + 1, y)、(x−1,y)(x - 1, y) 或 (x,y+1)(x, y + 1)(但不能放在 (x,y−1)(x, y - 1)),前提是该位置此前未被任何方块占据。

一个塔(tower) 由 ss 个方块构成,它们的位置为 (x,y),(x,y+1),…,(x,y+s−1)(x, y), (x, y + 1), \ldots, (x, y + s - 1),其中 (x,y)(x, y) 为某一起始位置,ss 为正整数。该塔的大小为 ss,即其所含方块的数量。一个颜色为 rr 的塔 是指其中所有方块的颜色均为 rr 的塔。

对每个颜色 rr(r=1,2,…,nr = 1, 2, \dots, n),独立求解以下问题:

  • 在遵守上述放置规则的前提下,你能构造出的颜色为 rr 的塔的最大可能大小是多少?

输入格式

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

The first line of each test case contains a single integer nn (1≤n≤1051 \le n \le 10^5).

The second line of each test case contains nn integers c1,c2,…,cnc_1, c_2, \ldots, c_n (1≤ci≤n1 \le c_i \le n).

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

第一行包含一个整数 tt(1≤t≤1041 \le t \le 10^4)—— 表示测试用例的数量。

每个测试用例的第一行包含一个整数 nn(1≤n≤1051 \le n \le 10^5)。

每个测试用例的第二行包含 nn 个整数 c1,c2,…,cnc_1, c_2, \ldots, c_n(1≤ci≤n1 \le c_i \le n)。

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

输出格式

For each test case, output nn integers. The rr-th of them should be the maximum size of an tower of color rr you can form by following the given rules. If you cannot form any tower of color rr, the rr-th integer should be 00.

对于每个测试用例,输出 nn 个整数。其中第 rr 个整数应为你能按照给定规则构造出的颜色为 rr 的塔的最大高度。若无法构造出任何颜色为 rr 的塔,则第 rr 个整数应为 00。

输入输出样例

  • 输入#1

    6
    7
    1 2 3 1 2 3 1
    6
    4 2 2 2 4 4
    1
    1
    5
    5 4 5 3 5
    6
    3 3 3 1 3 3
    8
    1 2 3 4 4 3 2 1

    输出#1

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

说明/提示

In the first test case, one of the possible ways to form a tower of color 11 and size 33 is:

  • place block 11 at position (0,0)(0, 0);
  • place block 22 to the right of block 11, at position (1,0)(1, 0);
  • place block 33 above block 22, at position (1,1)(1, 1);
  • place block 44 to the left of block 33, at position (0,1)(0, 1);
  • place block 55 to the left of block 44, at position (−1,1)(-1, 1);
  • place block 66 above block 55, at position (−1,2)(-1, 2);
  • place block 77 to the right of block 66, at position (0,2)(0, 2).

The blocks at positions (0,0)(0, 0), (0,1)(0, 1), and (0,2)(0, 2) all have color 11, forming an tower of size 33.

In the second test case, note that the following placement is not valid, since you are not allowed to place block 66 under block 55:

It can be shown that it is impossible to form a tower of color 44 and size 33.

在第一个测试用例中,构造一个颜色为 11、大小为 33 的塔的一种可能方式如下:

  • 将方块 11 放置在位置 (0,0)(0, 0);
  • 将方块 22 放置在方块 11 的右侧,即位置 (1,0)(1, 0);
  • 将方块 33 放置在方块 22 的上方,即位置 (1,1)(1, 1);
  • 将方块 44 放置在方块 33 的左侧,即位置 (0,1)(0, 1);
  • 将方块 55 放置在方块 44 的左侧,即位置 (−1,1)(-1, 1);
  • 将方块 66 放置在方块 55 的上方,即位置 (−1,2)(-1, 2);
  • 将方块 77 放置在方块 66 的右侧,即位置 (0,2)(0, 2)。

位于位置 (0,0)(0, 0)、(0,1)(0, 1) 和 (0,2)(0, 2) 的方块颜色均为 11,从而构成一个大小为 33 的塔。

在第二个测试用例中,请注意以下放置方式是无效的,因为你不允许将方块 66 放置在方块 55 的下方:

可以证明:无法构造一个颜色为 44、大小为 33 的塔。

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

首页