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;
const int maxn = 200005;
int n;
int a[maxn];
void fastIO()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
int main()
{
fastIO();
cin >> n;
for (int i = 1; i <= n; ++i)
{
cin >> a[i];
}
multiset<int> s;
stack<pair<int, int>> st;
for (int i = 1; i <= n; ++i)
{
if (s.find(a[i]) == s.end())
{
//cout << "here for " << i << endl;
st.push(make_pair(a[i], i));
s.insert(a[i]);
}
else
{
//cout << "popping on " << i << ' ' << st.size() << endl;
while (st.top().first != a[i])
{
//cout << "removing " << st.top().first << ' ' << st.top().second << endl;
s.erase(s.find(st.top().first));
st.pop();
}
}
}
int last = n;
while (!st.empty())
{
int col = st.top().first;
int idx = st.top().second;
st.pop();
for (int i = last; i >= idx; --i)
{
a[i] = col;
}
last = idx - 1;
}
for (int i = 1; i <= n; ++i)
{
cout << a[i] << "\n";
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |