这道题第一眼还以为是树状数组,于是乎打着打着也是能过的
const maxn=;
var n,i,j,maxx:longint;
h,l:array[..] of longint;
p:array[..] of longint;
function lowbit(x:longint):longint;
begin
exit(x and (-x));
end;
procedure insert(x,i:longint);
var tem:longint;
begin
tem:=x;
while tem<=maxx+ do
begin
p[tem]:=i;
tem:=tem+lowbit(tem);
end;
end;
function work(x:longint):longint;
var tem:longint;
begin
tem:=maxn;
while x> do
begin
if (p[x]<tem) and (p[x]<>) then tem:=p[x];
x:=x-lowbit(x);
end;
if tem=maxn then exit()
else exit(tem);
end;
begin
readln(n);
for i:= to n do
begin
readln(h[i]);
if h[i]>maxx then maxx:=h[i];
end;
for i:= to n do
h[i]:=maxx+-h[i];
l[n]:=;
insert(h[n],n);
for i:=n- downto do
begin
l[i]:=work(h[i]-);
insert(h[i],i);
end;
for i:= to n- do
writeln(l[i]);
write(l[n]);
end.
然而这道题正确解法是 单调栈!!
type
node=record
num,h:longint;
end;
var n,i,j,num,now:longint;
stack:array[..] of node;
h,l:array[..] of longint;
begin
readln(n);
for i:= to n do
readln(h[i]);
now:=;
for i:=n downto do
begin
while (now>) and (stack[now].h<=h[i]) do
dec(now);
l[i]:=stack[now].num;
inc(now);
stack[now].h:=h[i];
stack[now].num:=i;
end;
for i:= to n do writeln(l[i]);
end.
好吧,差不多,差不多=-=//
(转载请注明出处:http://www.cnblogs.com/Kalenda/)