https://codeforces.com/contest/1417/problem/C
I'm thinking about it at night..
The range of a1, a2,..., an (1≤ai≤n) actually implies the number of occurrences to be enumerated. But I don’t know how to look at 1e9 in a trance..
For each number, it is actually to consider the minimum length of k between the same numbers to be included. Enumerate the difference between a number and the beginning of the sequence, the middle number, and the last number and the end of the sequence. Use an ans[k] to record which is the smallest number of k with the minimum required length. ans[k]=min(ans[k],i);
Finally, pay attention to maintaining the smallest prefix of ans[k]. Because the length of 2 can be covered to the minimum length> 2 must be covered.
#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=3e5+100;
typedef long long LL;
const LL inf=1e18;
LL ans[maxn];
vector<LL>v[maxn];
int main(void)
{
cin.tie(0);std::ios::sync_with_stdio(false);
LL t;cin>>t;
while(t--)
{
LL n;cin>>n;
for(LL i=0;i<=n+10;i++) ans[i]=inf,v[i].clear();
for(LL i=1;i<=n;i++){
LL x;cin>>x;v[x].push_back(i);
}
for(LL i=1;i<=n;i++)
{
if(!v[i].empty())
{
LL mx=0;
for(LL j=1;j<v[i].size();j++)
{
mx=max(mx,v[i][j]-v[i][j-1]);
}
mx=max(mx,v[i].front());
mx=max(mx,n-v[i].back()+1);
ans[mx]=min(ans[mx],i);
}
}
for(LL i=2;i<=n;i++) ans[i]=min(ans[i],ans[i-1]);
for(LL i=1;i<=n;i++){
if(ans[i]<inf) cout<<ans[i]<<" ";
else cout<<"-1"<<" ";
}
cout<<endl;
}
return 0;
}