3401: [Usaco2009 Mar]Look Up 仰望

Time Limit: 3 Sec  Memory Limit: 128 MB
Submit: 136  Solved: 81
[Submit][Status][Discuss]

Description

约翰的N(1≤N≤105)头奶牛站成一排,奶牛i的身高是Hi(l≤Hi≤1,000,000).现在,每只奶牛都在向左看齐.对于奶牛i,如果奶牛j满足i<j且Hi<Hj,我们可以说奶牛i可以仰望奶牛j.    求出每只奶牛离她最近的仰望对象.

Input

 
    第1行输入N,之后每行输入一个身高.

Output

 
    共N行,按顺序每行输出一只奶牛的最近仰望对象.如果没有仰望对象,输出0.

Sample Input

6
3
2
6
1
1
2

Sample Output

3
3
0
6
6
0

HINT

 

Source

Silver

题解:再一次请出我神奇的小线段树——用线段树实现求在某某位置之后大于某值的最靠左位置,用了一个比较神奇的分治,具体如程序(发现线段是是个乱搞神器啊有木有)

 var
i,j,k,l,m,n:longint;
a,b:array[..] of longint;
function max(x,y:longint):longint;inline;
begin
if x>y then max:=x else max:=y;
end;
function min(x,y:longint):longint;inline;
begin
if x<y then min:=x else min:=y;
end;
procedure built(z,x,y:longint);inline;
begin
if x=y then
begin
read(a[z]);
b[x]:=a[z];
end
else
begin
built(z*,x,(x+y) div );
built(z*+,(x+y) div +,y);
a[z]:=max(a[z*],a[z*+]);
end;
end;
function approach(z,x,y,l,r,t:longint):longint;inline;
var a1:longint;
begin
if l>r then exit();
if a[z]<=t then exit();
if x=y then
begin
if a[z]>t then exit(x);
end;
a1:=approach(z*,x,(x+y) div ,l,min(r,(x+y) div ),t);
if a1<> then exit(a1);
exit(approach(z*+,(x+y) div +,y,max((x+y) div +,l),r,t));
end;
begin
readln(n);
built(,,n);
for i:= to n do
writeln(approach(,,n,i+,n,b[i])); end.

3401: [Usaco2009 Mar]Look Up 仰望的更多相关文章

  1. BZOJ 3401: [Usaco2009 Mar]Look Up 仰望( 单调栈 )

    n <= 105 , 其实是10 ^ 5 ....坑...我一开始写了个模拟结果就 RE 了.. 发现这个后写了个单调栈就 A 了... ---------------------------- ...

  2. 【BZOJ】3401: [Usaco2009 Mar]Look Up 仰望(单调栈)

    http://www.lydsy.com/JudgeOnline/problem.php?id=3401 还能更裸一些吗.. 维护一个递减的单调栈 #include <cstdio> #i ...

  3. BZOJ 3401: [Usaco2009 Mar]Look Up 仰望(离线+平衡树)

    刷银组刷得好开心= = 离线按权值排序,从大到小插入二叉树,查找树中比这个数大的 CODE: #include<cstdio>#include<iostream>#includ ...

  4. bzoj 3401: [Usaco2009 Mar]Look Up 仰望【单调栈】

    用单调递减的栈从后往前扫一遍即可 #include<iostream> #include<cstdio> using namespace std; const int N=10 ...

  5. BZOJ3401: [Usaco2009 Mar]Look Up 仰望

    3401: [Usaco2009 Mar]Look Up 仰望 Time Limit: 3 Sec  Memory Limit: 128 MBSubmit: 87  Solved: 58[Submit ...

  6. P3401: [Usaco2009 Mar]Look Up 仰望

    这道题第一眼还以为是树状数组,于是乎打着打着也是能过的 ; var n,i,j,maxx:longint; h,l:array[..] of longint; p:array[..] of longi ...

  7. bzoj 3399: [Usaco2009 Mar]Sand Castle城堡

    3399: [Usaco2009 Mar]Sand Castle城堡 Time Limit: 3 Sec  Memory Limit: 128 MB Description 约翰用沙子建了一座城堡.正 ...

  8. BZOJ3400: [Usaco2009 Mar]Cow Frisbee Team 奶牛沙盘队

    3400: [Usaco2009 Mar]Cow Frisbee Team 奶牛沙盘队 Time Limit: 3 Sec  Memory Limit: 128 MBSubmit: 89  Solve ...

  9. BZOJ3399: [Usaco2009 Mar]Sand Castle城堡

    3399: [Usaco2009 Mar]Sand Castle城堡 Time Limit: 3 Sec  Memory Limit: 128 MBSubmit: 22  Solved: 17[Sub ...

随机推荐

  1. globalToLocal的坐标变换

    globalToLocal $(function() { init(); }); // globalToLocal var stage, holder1, holder2,shape; functio ...

  2. Spring MVC URL的映射问题 ;Spring MVC 跳转与iframe包含地址问题

    /login/login.html 进行form提交,登录之后的页面位于/main/frame.jsp; 这样的controller中的地址需要映射成/main/login.do,然后在control ...

  3. CAGradientLayer颜色渐变器

    使用CAGradientLayer可以实现颜色的渐变, 我们先看下头文件 @interface CAGradientLayer : CALayer @property(nullable, copy) ...

  4. KB奇遇记(4):困难重重的选型

    在以往的工作经历中,虽然也会出现公司的一些规章制度,但我鲜少与其打交道,也极少听说.但是来KB这里,突然发现公司居然并没有给我配备电脑!!原因是制度上并没有写IT人员入职需要配备电脑,尔后通过特批流程 ...

  5. Ubuntu安装搜狗拼音

    p { margin-bottom: 0.25cm; direction: ltr; color: rgb(0, 0, 0); line-height: 120% } p.western { font ...

  6. [CSS3] 学习笔记-选择器详解(三)

    1.UI元素状态伪类选择器 在CSS3的选择器中,除了结构性伪类选择器外,还有一种UI元素伪类选择器.这些选择器的共同特征是:指定的样式只有当元素处于某种状态时才起作用,在默认状态下不起作用.在CSS ...

  7. ArcGIS三种方式打断相交线------拓扑法

    拓扑法:有多个layer图层相交线,选用拓扑法,将多个图层相交线打断. 新建拓扑结构: (1)单击新建"Nfg.gdb"数据库文件: (2)单击新建"XX"集合 ...

  8. JAVA函数的重载

    一.什么是重载(overlording) 在JAVA中,可以在同一个类中存在多个函数,函数名称相同但参数列表不同.这就是函数的重载(overlording).这是类的多太性表现之一. 二.重载的特征: ...

  9. JAVA中的小数

    JAVA中的小数称为浮点数 1.有两种类型: float:单精度浮点数.4个字节. double:双精度浮点数.8个字节. 2.类型转换 容量小  -------------------------- ...

  10. Python自然语言处理学习笔记之信息提取步骤&分块(chunking)

    一.信息提取模型 信息提取的步骤共分为五步,原始数据为未经处理的字符串, 第一步:分句,用nltk.sent_tokenize(text)实现,得到一个list of strings 第二步:分词,[ ...