1657: [Usaco2006 Mar]Mooo 奶牛的歌声

Time Limit: 5 Sec  Memory Limit: 64 MB
Submit: 526  Solved: 365
[Submit][Status]

Description

Farmer John's N (1 <= N <= 50,000) cows are standing in a very straight row and mooing. Each cow has a unique height h in the range 1..2,000,000,000 nanometers (FJ really is a stickler for precision). Each cow moos at some volume v in the range 1..10,000. This "moo" travels across the row of cows in both directions (except for the end cows, obviously). Curiously, it is heard only by the closest cow in each direction whose height is strictly larger than that of the mooing cow (so each moo will be heard by 0, 1 or 2 other cows, depending on not whether or taller cows exist to the mooing cow's right or left). The total moo volume heard by given cow is the sum of all the moo volumes v for all cows whose mooing reaches the cow. Since some (presumably taller) cows might be subjected to a very large moo volume, FJ wants to buy earmuffs for the cow whose hearing is most threatened. Please compute the loudest moo volume heard by any cow.

Farmer John的N(1<=N<=50,000)头奶牛整齐地站成一列“嚎叫”。每头奶牛有一个确定的高度h(1<=h<=2000000000),叫的音量为v (1<=v<=10000)。每头奶牛的叫声向两端传播,但在每个方向都只会被身高严格大于它的最近的一头奶牛听到,所以每个叫声都只会 被0,1,2头奶牛听到(这取决于它的两边有没有比它高的奶牛)。 一头奶牛听到的总音量为它听到的所有音量之和。自从一些奶牛遭受巨大的音量之后,Farmer John打算买一个耳罩给被残害得最厉 害的奶牛,请你帮他计算最大的总音量。

Input

* Line 1: A single integer, N.

* Lines 2..N+1: Line i+1 contains two space-separated integers, h and v, for the cow standing at location i.

第1行:一个正整数N.

第2到N+1行:每行包括2个用空格隔开的整数,分别代表站在队伍中第i个位置的奶牛的身高以及她唱歌时的音量.

Output

* Line 1: The loudest moo volume heard by any single cow.

队伍中的奶牛所能听到的最高的总音量.

Sample Input

3
4 2
3 5
6 10

INPUT DETAILS:

Three cows: the first one has height 4 and moos with volume 2, etc.

Sample Output

7

HINT

队伍中的第3头奶牛可以听到第1头和第2头奶牛的歌声,于是她能听到的总音量为2+5=7.虽然她唱歌时的音量为10,但并没有奶牛可以听见她的歌声.

Source

Silver

题解:萌萌哒我赶脚此题超级神似Bzoj1660,这道题还是直接线段树维护即可,方法类似bzoj1660(话说今天才发现bzoj1660里面的b数组根本没用到啊呵呵。。。)

 var
i,j,k,l,m,n:longint;
a,b,c,e:array[..] of longint;
function max(x,y:longint):longint;
begin
if x>y then max:=x else max:=y;
end;
function min(x,y:longint):longint;
begin
if x<y then min:=x else min:=y;
end;
procedure build(x,y,z:longint);
begin
if (x=y) then
begin
a[z]:=c[x];
b[z]:=x;
end
else
begin
build(x,(x+y) div ,z*);
build((x+y) div +,y,z*+);
a[z]:=max(a[z*],a[z*+]);
end;
end;
function getright(x,y,z,l,r,t:longint):longint;
var
i,j,k:longint;
begin
if l>r then exit(-);
if c[l]>t then exit(l);
if a[z]<=t then exit(-);
if (l=r) or (x=y) then exit(-); i:=getright(x,(x+y) div ,z*,l,min(r,(x+y) div ),t);
if i=- then
getright:=getright((x+y) div +,y,z*+,max(l,(x+y) div +),r,t)
else
getright:=i;
end;
function getleft(x,y,z,l,r,t:longint):longint;
var
i,j,k:longint;
begin
if l>r then exit(-);
if a[z]<=t then exit(-);
if c[r]>t then exit(r);
if (x=y) or (l=r) then exit(-); i:=getleft((x+y) div +,y,z*+,max(l,(x+y) div +),r,t);
if i=- then
getleft:=getleft(x,(x+y) div ,z*,l,min(r,(x+y) div ),t)
else
getleft:=i;
end;
begin
readln(n);
for i:= to n do
readln(c[i],e[i]);
build(,n,);
fillchar(b,sizeof(b),);
for i:= to n do
begin
j:=getleft(,n,,,i-,c[i]);
k:=getright(,n,,i+,n,c[i]);
if j<>- then b[j]:=b[j]+e[i];
if k<>- then b[k]:=b[k]+e[i];
end;
l:=;
for i:= to n do
l:=max(l,b[i]);
writeln(l);
end.

1657: [Usaco2006 Mar]Mooo 奶牛的歌声的更多相关文章

  1. Bzoj 1657: [Usaco2006 Mar]Mooo 奶牛的歌声 单调栈

    1657: [Usaco2006 Mar]Mooo 奶牛的歌声 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 631  Solved: 445[Submi ...

  2. 【BZOJ】1657: [Usaco2006 Mar]Mooo 奶牛的歌声(单调栈)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1657 这一题一开始我想到了nlog^2n的做法...显然可做,但是麻烦.(就是二分+rmq) 然后我 ...

  3. BZOJ 1657 [Usaco2006 Mar]Mooo 奶牛的歌声:单调栈【高度序列】

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1657 题意: Farmer John的N(1<=N<=50,000)头奶牛整齐 ...

  4. bzoj 1657 [Usaco2006 Mar]Mooo 奶牛的歌声——单调栈水题

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1657 #include<iostream> #include<cstdio ...

  5. bzoj 1657: [Usaco2006 Mar]Mooo 奶牛的歌声【单调栈】

    先考虑只能往一边传播,最后正反两边就行 一向右传播为例,一头牛能听到的嚎叫是他左边的牛中与高度严格小于他并且和他之间没有更高的牛,用单调递减的栈维护即可 #include<iostream> ...

  6. BZOJ1657: [Usaco2006 Mar]Mooo 奶牛的歌声

    1657: [Usaco2006 Mar]Mooo 奶牛的歌声 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 489  Solved: 338[Submi ...

  7. [Usaco2006 Mar]Mooo 奶牛的歌声(单调栈裸题)

    1657: [Usaco2006 Mar]Mooo 奶牛的歌声 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 961  Solved: 679[Submi ...

  8. [BZOJ1657] [Usaco2006 Mar] Mooo 奶牛的歌声 (单调栈)

    Description Farmer John's N (1 <= N <= 50,000) cows are standing in a very straight row and mo ...

  9. [Usaco2006 Mar]Mooo 奶牛的歌声

    Description Farmer John's N (1 <= N <= 50,000) cows are standing in a very straight row and mo ...

随机推荐

  1. PHP Memcached 实现简单数据库缓存

    Memcache常用方法 Memcache::add — 添加一个值,如果已经存在,则返回false Memcache::addServer — 添加一个可供使用的服务器地址 Memcache::cl ...

  2. 字符串的长度超过了为 maxJsonLength 属性设置的值

    当出现类似标题的错误时,可以按照如下方法解决: 1. 检查是否传递的JSON字符串长度过长 2.增加JSON串的长度设置,设置如下: <system.web.extensions>     ...

  3. Linux笔记(十三) - 系统管理

    (1)进程管理1.判断服务器健康状态2.查看进程a.查看系统中所有进程:ps    例:ps aux(使用BSD操作系统命令格式)    a 显示所有前台进程    x 显示所有后台进程    u 显 ...

  4. HTML5行业现状与未来 - 2016年终大盘点

    * { margin: 0; padding: 0 } .con { width: 802px; margin: 0 auto; text-align: center; position: inher ...

  5. JDK源码分析-AtomicInteger

    AtomicInteger可以看做Integer类的原子操作工具类.在java.util.concurrent.atomic包下,在一些使用场合下可以取代加锁操作提高并发性.接下来就从几个方面来介绍: ...

  6. CI Weekly #13 | 用更 Geek 的方式配置你的 CI 工作流

    flow.ci 的重大更新来了--支持通过 .yml 文件配置工作流(测试阶段),具体的使用方法可参考文档:同时 flow.ci 也开放了社区>> club.flow.ci,使用的任何问题 ...

  7. getstyle() 获取样式

    问题:在js动画中,如果元素设置了border,padding等,获取到的样式是盒子的样式,这样会影响动画的正常显示. 解决方案一:在元素的行内添加样式  如 <div style=" ...

  8. 面向UI编程:ui.js 1.0 粗糙版本发布,分布式开发+容器化+组件化+配置化框架,从无到有的艰难创造

    时隔第一次被UI思路激励,到现在1.0的粗糙版本发布,掐指一算整整半年了.半年之间,有些细节不断推翻重做,再推翻再重做.时隔今日,终于能先出来个东西了,这个版本很粗糙,主体功能大概能实现了,但是还是有 ...

  9. svg学习之旅(2)

    基本图形 circle 圆     cx基于X轴的坐标位置 cy基于y轴的坐标位置 r圆的半径 fill 填充 transparent透明 stroke 边框 stroke-width 边框宽度 st ...

  10. java测试之文件操作

    package filestream; import java.io.File; public class FileTester { public static void main(String [] ...