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()
{
cin.tie(0)->sync_with_stdio(0);
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++)
{
cin >> a[i];
}
map<int, pair<int, int>> mp;
vector<pair<int, pair<int, int>>> stk;
vector<int> ans(n);
for (int i = 0; i < n; i++)
{
if (mp.find(a[i]) != mp.end())
{
while (a[i] != stk.back().first)
{
mp.erase(stk.back().first);
stk.pop_back();
}
stk.back().second.second = i;
mp[a[i]].second = i;
}
else
{
mp[a[i]] = make_pair(i, i);
stk.emplace_back(a[i], make_pair(i, i));
}
}
for (auto &[c, pp] : mp)
{
auto &[l, r] = pp;
for (int i = l; i <= r; i++)
{
ans[i] = c;
}
}
for (int i = 0; i < n; i++)
{
cout << ans[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... |