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 = 2e5 + 25;
int a[MAXN], n;
int main () {
ios::sync_with_stdio(0); cin.tie(0);
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
stack <array <int, 3>> cur;
map <int, int> dd;
for (int i = 1; i <= n; i++) {
array <int, 3> l = {a[i], i, i};
if (dd[a[i]]) {
while (cur.top()[0] != a[i]) {
l[1] = cur.top()[1];
dd[cur.top()[0]]--;
cur.pop();
}
}
dd[a[i]]++;
cur.push(l);
}
int ans[n + 1] = {};
while (!cur.empty()) {
for (int i = cur.top()[1]; i <= cur.top()[2]; i++) ans[i] = cur.top()[0];
cur.pop();
}
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... |