这道题第一眼还以为是树状数组,于是乎打着打着也是能过的

 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/)

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

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

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

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

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

  3. 3401: [Usaco2009 Mar]Look Up 仰望

    3401: [Usaco2009 Mar]Look Up 仰望 Time Limit: 3 Sec  Memory Limit: 128 MBSubmit: 136  Solved: 81[Submi ...

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

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

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

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

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

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

  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. CSS3 伪类选择器 :nth-child()

    :nth-child()可以选择某个的一个或多个特定的子元素,你可以按这种方式进行选择: :nth-child(length);/*参数是具体数字*/ :nth-child(n);/*参数是n,n从0 ...

  2. 如果公司里有上百个表要做触发器,如果手动写代码的话。很累,所以今天写了一个小程序,自动生成mysql的触发代码。

    <?php $dbname = 'test';//数据库 $tab1 = 'user'; //执行的表 $tab2 = 'user_bak'; //被触发的表 $conn = mysql_con ...

  3. 安装node_modules文件遇到的问题:更改代理

    npm 1080 1081

  4. git gc

    git gc 有时候当你运行一些git命令(比如git pull)的时候,会有如下提示: 1 2 Auto packing the repository for optimum performance ...

  5. Mybatis配置

      首先导入mybatis-3.2.3.jar包 还有连接数据库的驱动包   工程中必须导入的三个包(对应的包附件中可以下载):   mybatis-3.2.3.jar sqljdbc.jar log ...

  6. Android事件

    1.Java package com.fish.helloworld; import android.app.Activity; import android.graphics.Color; impo ...

  7. string Format转义大括号:输入字符串的格式不正确。

    String.Format("{0} world!","hello") //将输出 hello world!,没有问题,但是只要在第一个参数的任意位置加上一个大 ...

  8. C++ STL 简单记录

    1,STL提供三种类型的组件:容器.迭代器.算法. 容器: 顺序容器(vector.list.deque.string等)是一系列元素的有序集合: 关联容器(set.multiset.map.mult ...

  9. CSS让div背景透明

    div背景透明样式: 样式代码: .alert{filter:alpha(opacity=100); /* IE */ -moz-opacity:1.0; /* Moz + FF */ opacity ...

  10. DataGridView 控件用法(可能不是很全面,因为这是自己常常用到的一些小总结):

    一.DataGridView属性设置 1.我们单击选中行的时候,默认是选择一个单元格,不能选择一整行,我们只需设置DataGridView的属性SelectionMode为FullRowSelect ...