[codeforces 1417C] k-Amazing Numbers

1417C

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include<bits/stdc++.h>
using namespace std;

const int maxn = 3e5+5;
int a[maxn],last[maxn],f[maxn],ans[maxn];


int main()
{
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
int t;
cin >> t;
while(t--)
{
int n;
cin >> n;
for(int i = 1; i <= n ; i++){
cin >> a[i];
last[i] = f[i] = 0;
ans[i] = -1;
}
for(int i = 1; i <= n; i++)
{
int x = a[i];
f[x] = max(f[x], i - last[x]);
last[x] = i;
}
for(int i = 1; i <= n; i++)
{
f[i] = max(f[i], n - last[i] + 1);
for(int j = f[i]; j <= n && ans[j] == -1;j++)
ans[j] = i;
}
for(int i = 1; i <= n; i++)
cout << ans[i] << ' ';
cout << endl;
}
}
  • Copyright: Copyright is owned by the author. For commercial reprints, please contact the author for authorization. For non-commercial reprints, please indicate the source.
  • Copyrights © 2020-2024 Rye
  • Visitors: | Views:

请我喝杯咖啡吧~

支付宝
微信