#include <bits/stdc++.h>
#define L(i, j, k) for(int i = (j); i <= (k); i++)
#define R(i, j, k) for(int i = (j); i >= (k); i--)
#define ll long long
#define sz(a) ((int) a.size())
#define all(a) a.begin(), a.end()
#define vi vector<ll>
#define pb emplace_back
#define me(a, x) memset(a, x, sizeof(a))
#define fst first
#define snd second
#define ii pair<ll, ll>
using namespace std;
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;cin>>n;
vi a(n);
L(i,0,n-1)cin>>a[i];
unordered_map<int,vi>id;
//~ cout<<"PASS"<<endl;
L(i,0,n-1){
//~ cout<<"PASS"<<endl;
//~ cout<<i<<" ";
if(sz(id[a[i]])>=1){
int idx=id[a[i]].back();
R(j,i-1,idx+1){
if(sz(id[a[j]]))id[a[j]].pop_back();
a[j]=a[i];
}
}
id[a[i]].pb(i);
}
L(i,0,n-1)cout<<a[i]<<endl;
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |