-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmikeFeet.cpp
More file actions
71 lines (55 loc) · 1.38 KB
/
mikeFeet.cpp
File metadata and controls
71 lines (55 loc) · 1.38 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// https://codeforces.com/problemset/problem/547/B
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int N = 1000005;
vector<int> tot (N);
vector<int> sets (N);
int find (int node) {
if (sets[node] == node) return node;
else return sets[node] = find(sets[node]);
}
void merge (int u, int v) {
int su = find(u);
int sv = find(v);
if (su == sv) return;
sets[sv] = su;
tot[su] += tot[sv];
}
int main ()
{
for (int i = 0; i < N; i++) {
sets[i] = i;
tot[i] = 1;
}
int n;
cin >> n;
vector<pair<int, int>> heights;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
heights.push_back(make_pair(x, i));
}
sort(heights.begin(), heights.end(), greater<pair<int, int>> ());
int currN = 1;
vector<bool> visited (n+1, false);
vector<int> final (n+1);
for (int i = 0; i < n; i++) {
int posit = heights[i].second;
int value = heights[i].first;
visited[posit] = true;
if (posit && visited[posit-1]) {
merge(posit, posit-1);
}
if (posit < n-1 && visited[posit+1]) {
merge(posit, posit+1);
}
int curs = tot[find(posit)];
while (currN <= curs) {
final[currN++] = value;
}
}
for (int i = 1; i <= n; i++) cout << final[i] << " ";
cout << "\n";
}