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>
#define int long long
using namespace std;
const int MX = 200005;
int n;
int a[MX];
void nhap(){
cin >> n;
for(int i=1; i<=n; i++) cin >> a[i];
}
void solve(){
stack<int> st;
map<int, vector<int>> mp;
for(int i=1; i<=n; i++){
if(mp[a[i]].size()){
int p = mp[a[i]].back();
while(st.size() && st.top() >= p){
int u = st.top();
st.pop();
if(mp[a[u]].size() && mp[a[u]].back() == u) mp[a[u]].pop_back();
}
}
mp[a[i]].push_back(i);
st.push(i);
}
int value = 0;
for(int i=n; i>=1; i--){
if(st.size() && i == st.top()){
value = a[st.top()];
st.pop();
}
a[i] = value;
}
for(int i=1; i<=n; i++) cout << a[i] << '\n';
}
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
nhap();
solve();
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... |