## GUPTA MECHANICAL

IN THIS WEBSITE I CAN TELL ALL ABOUT TECH. TIPS AND TRICKS APP REVIEWS AND UNBOXINGS ALSO TECH. NEWS .............

# [Solution] Making Towers Codeforces Solution

B. Making Towers
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You have a sequence of $n$ colored blocks. The color of the $i$-th block is ${c}_{i}$, an integer between $1$ and $n$.

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

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

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

For each color $r$ from $1$ to $n$, solve the following

problem independently:

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

The first line contains a single integer $t$ ($1\le t\le {10}^{4}$) — the number of test cases.

The first line of each test case contains a single integer $n$ ($1\le n\le {10}^{5}$).

The second line of each test case contains $n$ integers ${c}_{1},{c}_{2},\dots ,{c}_{n}$ ($1\le {c}_{i}\le n$).

Another String Minimization Problem Codeforces Solution

Making Towers Codeforces Solution

Qpwoeirut And The City Codeforces Solution

Chopping Carrots (Easy Version) Codeforces Solution

Chopping Carrots (Hard Version) Codeforces Solution

It is guaranteed that the sum of $n$ over all test cases does not exceed $2\cdot {10}^{5}$.

Output

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