C. k-Amazing Numbers

194 篇文章 1 订阅
9 篇文章 0 订阅

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;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值