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;
#define ll long long
#define fi first
#define se second
#define p(x,y) pair<ll,ll>(x,y)
#define BIT(i,x) ((x>>i)&1)
#define MASK(x) (1<<x)
#define ld long double
#define __builtin_popcount __builtin_popcountll
#define pll pair<ll,ll>
template<class T1,class T2>
bool maximize(T1 &x,const T2 &y)
{
if(x<y)
{
x=y;
return 1;
}
return 0;
}
template<class T1,class T2>
bool minimize(T1 &x,const T2 &y)
{
if(x>y)
{
x=y;
return 1;
}
return 0;
}
void online()
{
std::ios_base::sync_with_stdio(0);
cin.tie(0);
}
ll n;
int main()
{
online();
cin>>n;
set<pll> S;
vector<pll> vt;
for(int i=1;i<=n;i++)
{
ll x;
cin>>x;
if(vt.empty())
{
vt.emplace_back(x,i);
S.emplace(x,i);
continue;
}
bool flag=1;
auto z=S.lower_bound(p(x,i));
if(z!=S.begin())
{
z--;
if((*z).fi==x)
{
ll y=(*z).se;
while(vt.back().se>y)
{
S.erase(vt.back());
vt.pop_back();
}
flag=0;
}
}
if(flag)
{
S.emplace(x,i);
vt.emplace_back(x,i);
}
}
ll j=0,vl=0;
for(int i=1;i<=n;i++)
{
if(j<vt.size()&&vt[j].se==i)
{
vl=vt[j].fi;
j++;
}
cout<<vl<<'\n';
}
}
Compilation message (stderr)
Main.cpp: In function 'int main()':
Main.cpp:80:13: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
80 | if(j<vt.size()&&vt[j].se==i)
| ~^~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |