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 NM = 2e5;
int n, a[NM+5];
map <int, int> cnt;
stack <int> st;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
cnt[a[1]] = 1;
st.push(1);
for (int i = 2; i <= n; i++)
if (cnt[a[i]] > 0){
while (a[st.top()] != a[i]){
cnt[a[st.top()]]--;
st.pop();
}
st.pop();
st.push(i);
}
else{
cnt[a[i]] = 1;
st.push(i);
}
while (!st.empty()){
int cur = st.top(); st.pop();
if (!st.empty()){
for (int i = st.top()+1; i < cur; i++) a[i] = a[cur];
}
else{
for (int i = 1; i < cur; i++) a[i] = a[cur];
}
}
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... |