Pagini recente » Cod sursa (job #2202057) | Cod sursa (job #428434) | Cod sursa (job #1567943) | Cod sursa (job #2583814) | Cod sursa (job #3164989)
#include <set>
#include <iostream>
#include <vector>
#include <queue>
#include <unordered_map>
#include <bitset>
#include <algorithm>
#define INF 1e9
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
int main()
{
//freopen("in.txt", "r", stdin);
freopen("algsort.in", "r", stdin);
freopen("algsort.out", "w", stdout);
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n;
cin >> n;
vector <int> in(n);
/* Static predecessor */
set <int> st;
unordered_map <int, int> cnt_mp;
cnt_mp.max_load_factor(0.25);
cnt_mp.reserve(1024);
int max_item = 0;
for (int i = 0; i < n; i++)
{
cin >> in[i];
max_item = max(max_item, in[i]);
cnt_mp[in[i]]++;
st.insert(in[i]);
}
vector <int> ans;
auto st_pn = st.begin();
while (true)
{
int cnt_max = cnt_mp[max_item];
for (int i = 0; i < cnt_max; i++)
ans.push_back(max_item);
auto pn = st.lower_bound(max_item);
// no predecessor
if (st_pn == pn) break;
pn--;
max_item = *pn;
}
reverse(ans.begin(), ans.end());
for (auto item: ans) cout << item << ' ';
return 0;
}