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;
using ll = long long;
unordered_map<int, int> mp;
int a[200200];
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int n;
cin >> n;
stack<pair<int, int>> st;
for (int i = 1;i <= n;i++) {
int t;
cin >> t;
if (mp[t] != 0) {
while (!st.empty() && st.top().first != t) {
int v = st.top().first, idx = st.top().second;
st.pop();
if (st.empty()) mp[v] -= idx;
else mp[v] -= idx - st.top().second;
}
}
if (!st.empty()) mp[t] += i - st.top().second;
else mp[t] += i;
st.push({ t, i });
}
while (!st.empty()) a[st.top().second] = st.top().first, st.pop();
for (int i = n;i >= 1;i--) {
if (a[i] == 0) a[i] = a[i + 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... |