Pagini recente » Cod sursa (job #1602217) | Cod sursa (job #1405902) | Cod sursa (job #2687199) | Cod sursa (job #1895835) | Cod sursa (job #179770)
Cod sursa(job #179770)
program subsir_crescator_lgmax_O(NlogN);
var best,v,M,P:array[0..100002] of longint;
poz,n,i,l,maxim:longint;
f,g:text;
procedure afis;
var L:longint;
begin
if p[poz]>0 then
begin
l:=poz;
poz:=p[poz];
afis;
poz:=l;
end;
write(g,v[poz],' ');
end;
function cauta(x:longint):longint;
var li,ls,mij:longint;
ok:boolean;
begin
ok:=true;
li:=0;ls:=l;mij:=(li+ls) div 2;
while (li<=ls) and ok do
begin
if (v[m[mij]]<x) and (v[m[mij+1]]>=x) then
begin
ok:=false;
cauta:=mij;
end
else
if v[m[mij+1]]<x then
begin li:=mij+1;mij:=(li+ls) div 2; end
else
begin ls:=mij-1;mij:=(li+ls) div 2; end;
end;
if ok then cauta:=l;
end;
begin
assign(f,'scmax.in');reset(f);
assign(g,'scmax.out');rewrite(g);
readln(f,n);
for i:=1 to n do read(f,v[i]);
close(F);
m[1]:=1;best[1]:=1;p[1]:=1;l:=1;
for i:=2 to n do
begin
poz:=cauta(v[i]);
best[i]:=poz+1;
m[poz+1]:=i;
p[i]:=m[poz];
if l<poz+1 then l:=poz+1;
end;
maxim:=0;poz:=0;
for i:=1 to n do
if maxim<best[i] then begin
maxim:=best[i];poz:=i;
end;
writeln(g,maxim);
afis;
close(g);
end.