https://codeforces.ml/contest/1417/problem/C
You are given an array aa consisting of nn integers numbered from 11 to nn.
Let's define the kk-amazing number of the array as the minimum number that occurs in all of the subsegments of the array having length kk (recall that a subsegment of aa of length kk is a contiguous part of aa containing exactly kk elements). If there is no integer occuring in all subsegments of length kk for some value of kk, then the kk-amazing number is −1−1.
For each kk from 11 to nn calculate the kk-amazing number of the array aa.
Input
The first line contains one integer tt (1≤t≤10001≤t≤1000) — the number of test cases. Then tt test cases follow.
The first line of each test case contains one integer nn (1≤n≤3⋅1051≤n≤3⋅105) — the number of elements in the array. The second line contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤n1≤ai≤n) — the elements of the array.
It is guaranteed that the sum of nn over all test cases does not exceed 3⋅1053⋅105.
Output
For each test case print nn integers, where the ii-th integer is equal to the ii-amazing number of the array.
Example
input
Copy
3 5 1 2 3 4 5 5 4 4 4 4 2 6 1 3 1 5 3 1
output
Copy
-1 -1 3 2 1 -1 4 4 4 2 -1 -1 1 1 1 1
代码:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn=1e6+5;
const ll mod=1e9+7;
ll t,n,ans,k,cnt,s;
ll a[maxn];
ll b[maxn],c[maxn];
vector<ll>q[maxn];
int main()
{
cin>>t;
while(t--)
{
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>a[i];
b[i]=0;
c[i]=-1;
q[i].clear();
}
for(int i=1;i<=n;i++)
{
b[a[i]]++;
q[a[i]].push_back(i);
}
int rr=n;
for(int i=1;i<=n;i++)
{
if(b[i]>0)
{
int s=q[i].size();
int l=q[i][0],r=n-q[i][s-1]+1;
int max1=max(l,r);
//cout<<max1<<endl;
for(int j=1;j<s;j++)
{
int u=q[i][j];
int v=q[i][j-1];
max1=max(max1,u-v);
}
for(int j=max1;j<=rr;j++)
{
c[j]=i;
}
if(max1<=rr)
{
rr=max1-1;
}
}
}
for(int i=1;i<=n;i++)
{
cout<<c[i]<<" ";
}
cout<<endl;
}
return 0;
}