[BZOJ3401] [Usaco2009 Mar]Look Up 仰望

来源:互联网 发布:广东电信 网络测速 编辑:程序博客网 时间:2024/04/26 16:11

传送门

http://www.lydsy.com/JudgeOnline/problem.php?id=3401

题目大意

询问每一位置右边第一个比它大的数

题解

单调队列

var ans,x,t:array[0..200005]of longint; i,j,k:longint; n,tt,l,r,mid:longint;begin readln(n); for i:=1 to n do  readln(x[i]); tt:=1; t[1]:=n; ans[n]:=0; for i:=n-1 downto 1 do  begin   k:=1;   for j:=tt downto 1 do    if x[t[j]]>x[i]    then begin t[j+1]:=i; tt:=j+1; k:=0; break; end;   if k=1 then begin tt:=1; t[1]:=i; end;   if tt=1 then ans[i]:=0 else ans[i]:=t[tt-1];  end; for i:=1 to n do  writeln(ans[i]);end.
0 0
原创粉丝点击