#include <cstdio>
#include <cstring>
#include <cassert>
#include <string>
#include <deque>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#include <iostream>
#include <utility>
using namespace std;
using ll = long long;
using ld = long double;
#define ShinLena cin.tie(nullptr)->sync_with_stdio(false)
#define N 200005
#define ALL(x) x.begin(), x.end()
int n, a[N], b[N], c[N], C, t[N<<2], lz[N<<2];
vector<int> at[N];
void build(int v, int l, int r)
{
if (l == r) t[v] = a[l];
else build(2*v+1, l, (l+r)/2), build(2*v+2, (l+r)/2+1, r);
}
void push(int v, int l, int r)
{
if (lz[v])
{
if (l != r) lz[2*v+1] = lz[2*v+2] = lz[v];
t[v] = lz[v];
lz[v] = 0;
}
}
void upd(int v, int l, int r, int x, int y, int k)
{
push(v, l, r);
if (r < x||y<l)return;
if(x<=l&&r<=y){lz[v]=k;push(v,l,r);return;}
upd(2*v+1, l,(l+r)/2,x,y,k),upd(2*v+2,(l+r)/2+1,r,x,y,k);
}
int qry(int v,int l,int r,int p)
{
push(v,l,r);
if (l==r)return t[v];
if(p<=(l+r)/2)return qry(2*v+1,l,(l+r)/2,p);
return qry(2*v+2, (l+r)/2+1, r, p);
}
void ans(int v, int l, int r)
{
push(v,l,r);
if (l == r) a[l]= t[v];
else ans(2*v+1,l,(l+r)/2), ans(2*v+2, (l+r)/2+1,r);
}
int main()
{
ShinLena;
cin >> n;
for (int i = 1; i <= n; ++i) cin >> a[i], b[C++] = a[i];
sort(b, b+C); C = unique(b, b+C) - b;
for (int i = 1; i <= n; ++i) { int x = lower_bound(b, b+C, a[i]) - b + 1, old = a[i]; c[a[i] = x] = old; }
build(0,1,n);
for (int i = 1; i <= n; ++i)
{
while(at[a[i]].size() && qry(0,1,n,at[a[i]].back()) != a[i]) at[a[i]].pop_back();
if (at[a[i]].size()) upd(0, 1, n,at[a[i]].back()+1,i-1, a[i]);
at[a[i]].push_back(i);
}
ans(0,1,n);
for(int i=1;i<=n;++i)cout<<c[a[i]]<<'\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
8796 KB |
Output is correct |
2 |
Correct |
1 ms |
8796 KB |
Output is correct |
3 |
Correct |
1 ms |
8796 KB |
Output is correct |
4 |
Correct |
1 ms |
8796 KB |
Output is correct |
5 |
Correct |
1 ms |
8796 KB |
Output is correct |
6 |
Correct |
2 ms |
8796 KB |
Output is correct |
7 |
Correct |
1 ms |
8796 KB |
Output is correct |
8 |
Correct |
2 ms |
8840 KB |
Output is correct |
9 |
Correct |
1 ms |
8792 KB |
Output is correct |
10 |
Correct |
2 ms |
8796 KB |
Output is correct |
11 |
Correct |
2 ms |
8796 KB |
Output is correct |
12 |
Correct |
2 ms |
8796 KB |
Output is correct |
13 |
Correct |
2 ms |
8796 KB |
Output is correct |
14 |
Correct |
2 ms |
8844 KB |
Output is correct |
15 |
Correct |
2 ms |
8796 KB |
Output is correct |
16 |
Correct |
2 ms |
8792 KB |
Output is correct |
17 |
Correct |
2 ms |
8796 KB |
Output is correct |
18 |
Correct |
2 ms |
8796 KB |
Output is correct |
19 |
Correct |
2 ms |
8796 KB |
Output is correct |
20 |
Correct |
3 ms |
8904 KB |
Output is correct |
21 |
Correct |
2 ms |
8892 KB |
Output is correct |
22 |
Correct |
2 ms |
8792 KB |
Output is correct |
23 |
Correct |
2 ms |
8796 KB |
Output is correct |
24 |
Correct |
2 ms |
8796 KB |
Output is correct |
25 |
Correct |
2 ms |
8888 KB |
Output is correct |
26 |
Correct |
2 ms |
8792 KB |
Output is correct |
27 |
Correct |
2 ms |
8796 KB |
Output is correct |
28 |
Correct |
2 ms |
9048 KB |
Output is correct |
29 |
Correct |
2 ms |
8796 KB |
Output is correct |
30 |
Correct |
2 ms |
8860 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
8796 KB |
Output is correct |
2 |
Correct |
1 ms |
8796 KB |
Output is correct |
3 |
Correct |
1 ms |
8796 KB |
Output is correct |
4 |
Correct |
1 ms |
8796 KB |
Output is correct |
5 |
Correct |
2 ms |
8796 KB |
Output is correct |
6 |
Correct |
1 ms |
8796 KB |
Output is correct |
7 |
Correct |
2 ms |
8796 KB |
Output is correct |
8 |
Correct |
1 ms |
8796 KB |
Output is correct |
9 |
Correct |
2 ms |
8792 KB |
Output is correct |
10 |
Correct |
2 ms |
8792 KB |
Output is correct |
11 |
Correct |
2 ms |
8844 KB |
Output is correct |
12 |
Correct |
2 ms |
8796 KB |
Output is correct |
13 |
Correct |
2 ms |
8796 KB |
Output is correct |
14 |
Correct |
2 ms |
8796 KB |
Output is correct |
15 |
Correct |
2 ms |
8796 KB |
Output is correct |
16 |
Correct |
2 ms |
8796 KB |
Output is correct |
17 |
Correct |
59 ms |
13956 KB |
Output is correct |
18 |
Correct |
59 ms |
14100 KB |
Output is correct |
19 |
Correct |
63 ms |
13724 KB |
Output is correct |
20 |
Correct |
61 ms |
13520 KB |
Output is correct |
21 |
Correct |
61 ms |
13732 KB |
Output is correct |
22 |
Correct |
62 ms |
13524 KB |
Output is correct |
23 |
Correct |
60 ms |
13600 KB |
Output is correct |
24 |
Correct |
61 ms |
13520 KB |
Output is correct |
25 |
Correct |
60 ms |
13540 KB |
Output is correct |
26 |
Correct |
61 ms |
13516 KB |
Output is correct |
27 |
Correct |
63 ms |
13524 KB |
Output is correct |
28 |
Correct |
71 ms |
13588 KB |
Output is correct |
29 |
Correct |
60 ms |
13652 KB |
Output is correct |
30 |
Correct |
59 ms |
14020 KB |
Output is correct |
31 |
Correct |
59 ms |
14032 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
8796 KB |
Output is correct |
2 |
Correct |
1 ms |
8796 KB |
Output is correct |
3 |
Correct |
1 ms |
8796 KB |
Output is correct |
4 |
Correct |
1 ms |
8796 KB |
Output is correct |
5 |
Correct |
1 ms |
8796 KB |
Output is correct |
6 |
Correct |
2 ms |
8796 KB |
Output is correct |
7 |
Correct |
1 ms |
8796 KB |
Output is correct |
8 |
Correct |
2 ms |
8840 KB |
Output is correct |
9 |
Correct |
1 ms |
8792 KB |
Output is correct |
10 |
Correct |
2 ms |
8796 KB |
Output is correct |
11 |
Correct |
2 ms |
8796 KB |
Output is correct |
12 |
Correct |
2 ms |
8796 KB |
Output is correct |
13 |
Correct |
2 ms |
8796 KB |
Output is correct |
14 |
Correct |
2 ms |
8844 KB |
Output is correct |
15 |
Correct |
2 ms |
8796 KB |
Output is correct |
16 |
Correct |
2 ms |
8792 KB |
Output is correct |
17 |
Correct |
2 ms |
8796 KB |
Output is correct |
18 |
Correct |
2 ms |
8796 KB |
Output is correct |
19 |
Correct |
2 ms |
8796 KB |
Output is correct |
20 |
Correct |
3 ms |
8904 KB |
Output is correct |
21 |
Correct |
2 ms |
8892 KB |
Output is correct |
22 |
Correct |
2 ms |
8792 KB |
Output is correct |
23 |
Correct |
2 ms |
8796 KB |
Output is correct |
24 |
Correct |
2 ms |
8796 KB |
Output is correct |
25 |
Correct |
2 ms |
8888 KB |
Output is correct |
26 |
Correct |
2 ms |
8792 KB |
Output is correct |
27 |
Correct |
2 ms |
8796 KB |
Output is correct |
28 |
Correct |
2 ms |
9048 KB |
Output is correct |
29 |
Correct |
2 ms |
8796 KB |
Output is correct |
30 |
Correct |
2 ms |
8860 KB |
Output is correct |
31 |
Correct |
2 ms |
8796 KB |
Output is correct |
32 |
Correct |
1 ms |
8796 KB |
Output is correct |
33 |
Correct |
1 ms |
8796 KB |
Output is correct |
34 |
Correct |
1 ms |
8796 KB |
Output is correct |
35 |
Correct |
2 ms |
8796 KB |
Output is correct |
36 |
Correct |
1 ms |
8796 KB |
Output is correct |
37 |
Correct |
2 ms |
8796 KB |
Output is correct |
38 |
Correct |
1 ms |
8796 KB |
Output is correct |
39 |
Correct |
2 ms |
8792 KB |
Output is correct |
40 |
Correct |
2 ms |
8792 KB |
Output is correct |
41 |
Correct |
2 ms |
8844 KB |
Output is correct |
42 |
Correct |
2 ms |
8796 KB |
Output is correct |
43 |
Correct |
2 ms |
8796 KB |
Output is correct |
44 |
Correct |
2 ms |
8796 KB |
Output is correct |
45 |
Correct |
2 ms |
8796 KB |
Output is correct |
46 |
Correct |
2 ms |
8796 KB |
Output is correct |
47 |
Correct |
59 ms |
13956 KB |
Output is correct |
48 |
Correct |
59 ms |
14100 KB |
Output is correct |
49 |
Correct |
63 ms |
13724 KB |
Output is correct |
50 |
Correct |
61 ms |
13520 KB |
Output is correct |
51 |
Correct |
61 ms |
13732 KB |
Output is correct |
52 |
Correct |
62 ms |
13524 KB |
Output is correct |
53 |
Correct |
60 ms |
13600 KB |
Output is correct |
54 |
Correct |
61 ms |
13520 KB |
Output is correct |
55 |
Correct |
60 ms |
13540 KB |
Output is correct |
56 |
Correct |
61 ms |
13516 KB |
Output is correct |
57 |
Correct |
63 ms |
13524 KB |
Output is correct |
58 |
Correct |
71 ms |
13588 KB |
Output is correct |
59 |
Correct |
60 ms |
13652 KB |
Output is correct |
60 |
Correct |
59 ms |
14020 KB |
Output is correct |
61 |
Correct |
59 ms |
14032 KB |
Output is correct |
62 |
Correct |
69 ms |
17100 KB |
Output is correct |
63 |
Correct |
84 ms |
23344 KB |
Output is correct |
64 |
Correct |
83 ms |
23380 KB |
Output is correct |
65 |
Correct |
73 ms |
16432 KB |
Output is correct |
66 |
Correct |
71 ms |
16520 KB |
Output is correct |
67 |
Correct |
73 ms |
16704 KB |
Output is correct |
68 |
Correct |
70 ms |
16768 KB |
Output is correct |
69 |
Correct |
70 ms |
16592 KB |
Output is correct |
70 |
Correct |
70 ms |
16592 KB |
Output is correct |
71 |
Correct |
69 ms |
16768 KB |
Output is correct |
72 |
Correct |
70 ms |
16600 KB |
Output is correct |
73 |
Correct |
77 ms |
19620 KB |
Output is correct |
74 |
Correct |
108 ms |
19796 KB |
Output is correct |
75 |
Correct |
83 ms |
23380 KB |
Output is correct |
76 |
Correct |
81 ms |
23328 KB |
Output is correct |
77 |
Correct |
93 ms |
23636 KB |
Output is correct |
78 |
Correct |
82 ms |
23340 KB |
Output is correct |