time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
You have a sequence of nn colored blocks. The color of the ii-th block is cici, an integer between 11 and nn.
You will place the blocks down in sequence on an infinite coordinate grid in the following way.
- Initially, you place block 11 at (0,0)(0,0).
- For 2≤i≤n2≤i≤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),…,(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.
Input
The first line contains a single integer tt (1≤t≤1041≤t≤104) — the number of test cases.
The first line of each test case contains a single integer nn (1≤n≤1051≤n≤105).
The second line of each test case contains nn integers c1,c2,…,cnc1,c2,…,cn (1≤ci≤n1≤ci≤n).
It is guaranteed that the sum of nn over all test cases does not exceed 2⋅1052⋅105.
Output
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.
Example
input
Copy
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
output
Copy
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
Note
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.
#include <climits>
#include<iostream>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include<queue>
#include<vector>
#include<stack>
#include<math.h>
#define ll long long
using namespace std;
typedef pair <double , double> PII;
const int inf = 0x3f3f3f3f;
const int N = 1e5+5;
int T;
vector<int>vis[N];
int dp[N];
int main()
{
ios::sync_with_stdio(false);
cin >> T;
while (T--)
{
int n;
cin >> n;
for (int i = 1; i <= n; i++)
{
int a;
cin >> a;
vis[a].push_back(i); //将相同颜色的编号存起来,方便遍历
}
for (int i = 1; i <= n; i++)
{
int ans = 0;
if (vis[i].size()) {
ans = 1;
for (int j = 1; j < vis[i].size(); j++)
{
if ((vis[i][j] - vis[i][j - 1] - 1) % 2 == 0)ans++;
} //相同色块之间的距离是偶数就直接++。可以分别证明出,奇偶,偶奇,偶偶
//都是直接加1,所以直接看当前位置与上一个位置即可
}
cout << ans<<' ';
vis[i].clear();
}
cout << endl;
}
return 0;
}