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 endl '\n'
#define fi first
#define se second
using namespace std;
typedef long long ll;
const int N=200005;
int a[N],b[N];
void solve()
{
int n;
cin >> n;
map<int,vector<int>> m;
for(int i=1,l=0,r=0;i<=n;i++)
{
cin >> a[i];
int x=a[i];
if(m[x].size())
{
if(m[x].back()>=r)
{
l=m[x].back();r=i;
b[l]=r;
}
else if(m[x][0]<l)
{
int y=lower_bound(m[x].begin(),m[x].end(),l)-m[x].begin();
y--;
l=m[x][y],r=i;
b[l]=r;
}
}
m[x].push_back(i);
}
int temp=0;
for(int i=1;i<=n;i++)
{
if(!temp) temp=max(temp,b[i]);
if(temp==i) temp=0;
if(!temp) cout << a[i] << ' '; else cout << a[temp] << ' ';
}
}
int main()
{
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
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... |