이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
using namespace std;
int n,ant,act;
bool aint[800010];
bool valoare(int poz,int b,int e,int pozc)
{
if(b==e)
return aint[poz];
if((b+e)/2>=pozc)
return valoare(poz*2,b,(b+e)/2,pozc);
return valoare(poz*2+1,(b+e)/2+1,e,pozc);
}
void blocheaza(int poz,int b,int e,int pozu)
{
if(pozu<b||pozu>e)
return;
if(b==e)
{
aint[poz]=true;
return;
}
blocheaza(poz*2,b,(b+e)/2,pozu);
blocheaza(poz*2+1,(b+e)/2+1,e,pozu);
aint[poz]=(aint[poz*2]&aint[poz*2+1]);
}
int maxim(int poz,int b,int e)
{
if(b==e)
return b;
if(aint[poz*2+1]==false)
return maxim(poz*2+1,(b+e)/2+1,e);
return maxim(poz*2,b,(b+e)/2);
}
int minim(int poz,int b,int e)
{
if(b==e)
return b;
if(aint[poz*2]==false)
return minim(poz*2,b,(b+e)/2);
return minim(poz*2+1,(b+e)/2+1,e);
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>n>>ant;
cout<<ant<<' ';
blocheaza(1,1,2*n-1,ant);
for(int i=2;i<=n;++i)
{
cin>>act;
if(act>ant)
{
if(valoare(1,1,2*n-1,act)==false)
{
cout<<act<<' ';
blocheaza(1,1,2*n-1,act);
}
else
{
ant=maxim(1,1,2*n-1);
cout<<ant<<' ';
blocheaza(1,1,2*n-1,ant);
}
ant=maxim(1,1,2*n-1);
cout<<ant<<' ';
blocheaza(1,1,2*n-1,ant);
}
else if(act<ant)
{
if(valoare(1,1,2*n-1,act)==false)
{
cout<<act<<' ';
blocheaza(1,1,2*n-1,act);
}
else
{
ant=minim(1,1,2*n-1);
cout<<ant<<' ';
blocheaza(1,1,2*n-1,ant);
}
ant=minim(1,1,2*n-1);
cout<<ant<<' ';
blocheaza(1,1,2*n-1,ant);
}
else
{
ant=minim(1,1,2*n-1);
cout<<ant<<' ';
blocheaza(1,1,2*n-1,ant);
ant=maxim(1,1,2*n-1);
cout<<ant<<' ';
blocheaza(1,1,2*n-1,ant);
}
ant=act;
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |