#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
using namespace std;
using ar = array<int, 2>;
const int64_t INF = 1ll << 60;
const int N = 2e5 + 5;
namespace dsu {
int dpr[N], col[N], cnt[N];
int gpr(int x) {
return dpr[x] == x ? x : dpr[x] = gpr(dpr[x]);
}
void merge(int L, int R) {
R = gpr(R);
L = gpr(L);
if (L == R) return;
--cnt[col[R]];
dpr[R] = L;
}
}
int n, a[N], A[N];
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
iota(dsu::dpr, dsu::dpr + N, 0);
dsu::cnt[0] = N;
cin >> n;
FOR(i, 0, n) cin >> a[i];
copy(a, a + n, A);
sort(A, A + n);
FOR(i, 0, n) a[i] = lower_bound(A, A + n, a[i]) - A + 1;
FOR(i, 0, n) {
#define a a[i]
if (dsu::cnt[a]) {
for (int r = i - 1; r >= 0 && dsu::col[dsu::gpr(r)] != a; r = dsu::gpr(r - 1)) {
assert(r > 0);
dsu::merge(r, i);
}
}
int x = dsu::gpr(i);
--dsu::cnt[dsu::col[x]];
dsu::col[x] = a;
++dsu::cnt[dsu::col[x]];
}
FOR(i, 0, n) cout << A[dsu::col[dsu::gpr(i)] - 1] << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
3164 KB |
Output is correct |
2 |
Correct |
1 ms |
3164 KB |
Output is correct |
3 |
Correct |
1 ms |
3164 KB |
Output is correct |
4 |
Correct |
1 ms |
3164 KB |
Output is correct |
5 |
Correct |
1 ms |
3164 KB |
Output is correct |
6 |
Correct |
1 ms |
3164 KB |
Output is correct |
7 |
Correct |
1 ms |
3164 KB |
Output is correct |
8 |
Correct |
1 ms |
3164 KB |
Output is correct |
9 |
Correct |
1 ms |
3164 KB |
Output is correct |
10 |
Correct |
2 ms |
3164 KB |
Output is correct |
11 |
Correct |
1 ms |
3164 KB |
Output is correct |
12 |
Correct |
1 ms |
3164 KB |
Output is correct |
13 |
Correct |
1 ms |
3164 KB |
Output is correct |
14 |
Correct |
2 ms |
3164 KB |
Output is correct |
15 |
Correct |
1 ms |
3160 KB |
Output is correct |
16 |
Correct |
1 ms |
3164 KB |
Output is correct |
17 |
Correct |
1 ms |
3164 KB |
Output is correct |
18 |
Correct |
1 ms |
3164 KB |
Output is correct |
19 |
Correct |
1 ms |
3164 KB |
Output is correct |
20 |
Correct |
2 ms |
3288 KB |
Output is correct |
21 |
Correct |
1 ms |
3164 KB |
Output is correct |
22 |
Correct |
1 ms |
3164 KB |
Output is correct |
23 |
Correct |
1 ms |
3164 KB |
Output is correct |
24 |
Correct |
1 ms |
3316 KB |
Output is correct |
25 |
Correct |
1 ms |
3164 KB |
Output is correct |
26 |
Correct |
1 ms |
3164 KB |
Output is correct |
27 |
Correct |
1 ms |
3296 KB |
Output is correct |
28 |
Correct |
1 ms |
3164 KB |
Output is correct |
29 |
Correct |
1 ms |
3164 KB |
Output is correct |
30 |
Correct |
2 ms |
3164 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
3160 KB |
Output is correct |
2 |
Correct |
1 ms |
3160 KB |
Output is correct |
3 |
Correct |
1 ms |
3164 KB |
Output is correct |
4 |
Correct |
1 ms |
3164 KB |
Output is correct |
5 |
Correct |
2 ms |
3164 KB |
Output is correct |
6 |
Correct |
1 ms |
3164 KB |
Output is correct |
7 |
Correct |
1 ms |
3164 KB |
Output is correct |
8 |
Correct |
1 ms |
3164 KB |
Output is correct |
9 |
Correct |
1 ms |
3164 KB |
Output is correct |
10 |
Correct |
1 ms |
3164 KB |
Output is correct |
11 |
Correct |
1 ms |
3164 KB |
Output is correct |
12 |
Correct |
1 ms |
3164 KB |
Output is correct |
13 |
Correct |
1 ms |
3416 KB |
Output is correct |
14 |
Correct |
1 ms |
3164 KB |
Output is correct |
15 |
Correct |
2 ms |
3172 KB |
Output is correct |
16 |
Correct |
1 ms |
3176 KB |
Output is correct |
17 |
Correct |
28 ms |
4704 KB |
Output is correct |
18 |
Correct |
23 ms |
4440 KB |
Output is correct |
19 |
Correct |
29 ms |
4572 KB |
Output is correct |
20 |
Correct |
28 ms |
4444 KB |
Output is correct |
21 |
Correct |
29 ms |
4444 KB |
Output is correct |
22 |
Correct |
29 ms |
4444 KB |
Output is correct |
23 |
Correct |
28 ms |
4444 KB |
Output is correct |
24 |
Correct |
34 ms |
4696 KB |
Output is correct |
25 |
Correct |
28 ms |
4444 KB |
Output is correct |
26 |
Correct |
34 ms |
4760 KB |
Output is correct |
27 |
Correct |
28 ms |
4556 KB |
Output is correct |
28 |
Correct |
29 ms |
4444 KB |
Output is correct |
29 |
Correct |
24 ms |
4440 KB |
Output is correct |
30 |
Correct |
26 ms |
4432 KB |
Output is correct |
31 |
Correct |
23 ms |
4432 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
3164 KB |
Output is correct |
2 |
Correct |
1 ms |
3164 KB |
Output is correct |
3 |
Correct |
1 ms |
3164 KB |
Output is correct |
4 |
Correct |
1 ms |
3164 KB |
Output is correct |
5 |
Correct |
1 ms |
3164 KB |
Output is correct |
6 |
Correct |
1 ms |
3164 KB |
Output is correct |
7 |
Correct |
1 ms |
3164 KB |
Output is correct |
8 |
Correct |
1 ms |
3164 KB |
Output is correct |
9 |
Correct |
1 ms |
3164 KB |
Output is correct |
10 |
Correct |
2 ms |
3164 KB |
Output is correct |
11 |
Correct |
1 ms |
3164 KB |
Output is correct |
12 |
Correct |
1 ms |
3164 KB |
Output is correct |
13 |
Correct |
1 ms |
3164 KB |
Output is correct |
14 |
Correct |
2 ms |
3164 KB |
Output is correct |
15 |
Correct |
1 ms |
3160 KB |
Output is correct |
16 |
Correct |
1 ms |
3164 KB |
Output is correct |
17 |
Correct |
1 ms |
3164 KB |
Output is correct |
18 |
Correct |
1 ms |
3164 KB |
Output is correct |
19 |
Correct |
1 ms |
3164 KB |
Output is correct |
20 |
Correct |
2 ms |
3288 KB |
Output is correct |
21 |
Correct |
1 ms |
3164 KB |
Output is correct |
22 |
Correct |
1 ms |
3164 KB |
Output is correct |
23 |
Correct |
1 ms |
3164 KB |
Output is correct |
24 |
Correct |
1 ms |
3316 KB |
Output is correct |
25 |
Correct |
1 ms |
3164 KB |
Output is correct |
26 |
Correct |
1 ms |
3164 KB |
Output is correct |
27 |
Correct |
1 ms |
3296 KB |
Output is correct |
28 |
Correct |
1 ms |
3164 KB |
Output is correct |
29 |
Correct |
1 ms |
3164 KB |
Output is correct |
30 |
Correct |
2 ms |
3164 KB |
Output is correct |
31 |
Correct |
1 ms |
3160 KB |
Output is correct |
32 |
Correct |
1 ms |
3160 KB |
Output is correct |
33 |
Correct |
1 ms |
3164 KB |
Output is correct |
34 |
Correct |
1 ms |
3164 KB |
Output is correct |
35 |
Correct |
2 ms |
3164 KB |
Output is correct |
36 |
Correct |
1 ms |
3164 KB |
Output is correct |
37 |
Correct |
1 ms |
3164 KB |
Output is correct |
38 |
Correct |
1 ms |
3164 KB |
Output is correct |
39 |
Correct |
1 ms |
3164 KB |
Output is correct |
40 |
Correct |
1 ms |
3164 KB |
Output is correct |
41 |
Correct |
1 ms |
3164 KB |
Output is correct |
42 |
Correct |
1 ms |
3164 KB |
Output is correct |
43 |
Correct |
1 ms |
3416 KB |
Output is correct |
44 |
Correct |
1 ms |
3164 KB |
Output is correct |
45 |
Correct |
2 ms |
3172 KB |
Output is correct |
46 |
Correct |
1 ms |
3176 KB |
Output is correct |
47 |
Correct |
28 ms |
4704 KB |
Output is correct |
48 |
Correct |
23 ms |
4440 KB |
Output is correct |
49 |
Correct |
29 ms |
4572 KB |
Output is correct |
50 |
Correct |
28 ms |
4444 KB |
Output is correct |
51 |
Correct |
29 ms |
4444 KB |
Output is correct |
52 |
Correct |
29 ms |
4444 KB |
Output is correct |
53 |
Correct |
28 ms |
4444 KB |
Output is correct |
54 |
Correct |
34 ms |
4696 KB |
Output is correct |
55 |
Correct |
28 ms |
4444 KB |
Output is correct |
56 |
Correct |
34 ms |
4760 KB |
Output is correct |
57 |
Correct |
28 ms |
4556 KB |
Output is correct |
58 |
Correct |
29 ms |
4444 KB |
Output is correct |
59 |
Correct |
24 ms |
4440 KB |
Output is correct |
60 |
Correct |
26 ms |
4432 KB |
Output is correct |
61 |
Correct |
23 ms |
4432 KB |
Output is correct |
62 |
Correct |
36 ms |
8020 KB |
Output is correct |
63 |
Correct |
68 ms |
8276 KB |
Output is correct |
64 |
Correct |
69 ms |
8224 KB |
Output is correct |
65 |
Correct |
42 ms |
7760 KB |
Output is correct |
66 |
Correct |
37 ms |
7764 KB |
Output is correct |
67 |
Correct |
44 ms |
8016 KB |
Output is correct |
68 |
Correct |
39 ms |
8172 KB |
Output is correct |
69 |
Correct |
45 ms |
8100 KB |
Output is correct |
70 |
Correct |
41 ms |
8016 KB |
Output is correct |
71 |
Correct |
44 ms |
8016 KB |
Output is correct |
72 |
Correct |
44 ms |
8020 KB |
Output is correct |
73 |
Correct |
68 ms |
7952 KB |
Output is correct |
74 |
Correct |
67 ms |
7688 KB |
Output is correct |
75 |
Correct |
72 ms |
8196 KB |
Output is correct |
76 |
Correct |
68 ms |
8528 KB |
Output is correct |
77 |
Correct |
65 ms |
8200 KB |
Output is correct |
78 |
Correct |
64 ms |
8272 KB |
Output is correct |