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;
map <int, vector <int>> mp;
vector <int> ans(n+1);
for (int i = 1; i <= n; i++) {
cin >> ans[i];
if (!mp[ans[i]].empty()) {
int lst = mp[ans[i]].back();
for (int j = lst+1; j < i; j++) {
mp[ans[j]].pop_back();
mp[ans[i]].push_back(j);
ans[j] = ans[i];
}
}
mp[ans[i]].push_back(i);
}
for (int i = 1; i <= n; i++)
cout << ans[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... |