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];
unordered_map<int, vector<int>> last;
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];
}
for (int i = 1; i <= n; ++i)
{
if (last.find(a[i]) != last.end() && !last[a[i]].empty())
{
for (int j = last[a[i]].back() + 1; j <= i - 1; ++j)
{
last[a[j]].pop_back();
if (last[a[j]].empty())
{
last.erase(a[j]);
}
a[j] = a[i];
}
}
last[a[i]].push_back(i);
}
//cout << "--------------------------" << endl;
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... |