This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin >> n;
vector<int> v(n);
for (int& i : v) cin >> i;
vector<int> compress = v;
sort(compress.begin(), compress.end());
for (int& i : v)
i = lower_bound(compress.begin(), compress.end(), i) - compress.begin();
vector<int> nxt(n, -1), last(n, -1), res(n);
for (int i = n-1; i >= 0; i--)
{
if (last[v[i]] == -1)
last[v[i]] = i;
else
nxt[i] = last[v[i]];
}
for (int i = 0; i < n; i++)
{
if (nxt[i] != -1)
{
int j = nxt[i];
while (i < j) res[i++] = compress[v[j]];
res[i] = compress[v[j]];
}
else
res[i] = compress[v[i]];
}
for (int i : res)
cout << i << "\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |