1657: [Usaco2006 Mar]Mooo 奶牛的歌声
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
4 2
3 5
6 10
INPUT DETAILS:
Three cows: the first one has height 4 and moos with volume 2, etc.
Sample Output
HINT
队伍中的第3头奶牛可以听到第1头和第2头奶牛的歌声,于是她能听到的总音量为2+5=7.虽然她唱歌时的音量为10,但并没有奶牛可以听见她的歌声.
Source
题解:萌萌哒我赶脚此题超级神似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 奶牛的歌声的更多相关文章
- Bzoj 1657: [Usaco2006 Mar]Mooo 奶牛的歌声 单调栈
1657: [Usaco2006 Mar]Mooo 奶牛的歌声 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 631 Solved: 445[Submi ...
- 【BZOJ】1657: [Usaco2006 Mar]Mooo 奶牛的歌声(单调栈)
http://www.lydsy.com/JudgeOnline/problem.php?id=1657 这一题一开始我想到了nlog^2n的做法...显然可做,但是麻烦.(就是二分+rmq) 然后我 ...
- BZOJ 1657 [Usaco2006 Mar]Mooo 奶牛的歌声:单调栈【高度序列】
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1657 题意: Farmer John的N(1<=N<=50,000)头奶牛整齐 ...
- bzoj 1657 [Usaco2006 Mar]Mooo 奶牛的歌声——单调栈水题
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1657 #include<iostream> #include<cstdio ...
- bzoj 1657: [Usaco2006 Mar]Mooo 奶牛的歌声【单调栈】
先考虑只能往一边传播,最后正反两边就行 一向右传播为例,一头牛能听到的嚎叫是他左边的牛中与高度严格小于他并且和他之间没有更高的牛,用单调递减的栈维护即可 #include<iostream> ...
- BZOJ1657: [Usaco2006 Mar]Mooo 奶牛的歌声
1657: [Usaco2006 Mar]Mooo 奶牛的歌声 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 489 Solved: 338[Submi ...
- [Usaco2006 Mar]Mooo 奶牛的歌声(单调栈裸题)
1657: [Usaco2006 Mar]Mooo 奶牛的歌声 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 961 Solved: 679[Submi ...
- [BZOJ1657] [Usaco2006 Mar] Mooo 奶牛的歌声 (单调栈)
Description Farmer John's N (1 <= N <= 50,000) cows are standing in a very straight row and mo ...
- [Usaco2006 Mar]Mooo 奶牛的歌声
Description Farmer John's N (1 <= N <= 50,000) cows are standing in a very straight row and mo ...
随机推荐
- Java线程:同步
一 同步的概念 线程的同步是为了防止多个线程访问一个数据对象时,对数据造成的破坏. 例如:两个线程ThreadA.ThreadB都操作同一个对象Foo对象,并修改Foo对象上的数据. MyRunnab ...
- V8 Javascript 引擎设计理念
Netscape Navigator 在 90 在年代中期对 JavaScript 进行了集成,这让网页开发人员对 HTML 页面中诸如 form .frame 和 image 之类的元素的访问变得非 ...
- Weex系列一、构建Weex工程
Weex比React Native更简单,更容易学习,并且做到真正的跨平台,一套代码可以多个平台运行.所以建议大家都用Weex吧. 一.安装Node 已经安装Node的,请忽略过去. 检查Node是否 ...
- css3 3d学习心得
css3 3d学习心得 卡片反转 魔方 banner图 首先我们要学习好css3 3d一定要有一定的立体感 通过这个图片应该清楚的了解到了x轴 y轴 z轴是什么概念了. 首先先给大家看一个小例子: 卡 ...
- unity中锁定鼠标移动&&隐藏鼠标&&强制是鼠标移动到某一位置
[System.Runtime.InteropServices.DllImport("user32.dll")] //引入dll public static extern int ...
- 从C#到TypeScript - 类
总目录 从C#到TypeScript - 类型 从C#到TypeScript - 高级类型 从C#到TypeScript - 变量 从C#到TypeScript - 接口 从C#到TypeScript ...
- 搭建Eclipse开发和调试环境(真机)
由于工作原因,最近开始了Android开发.之前接触过一段时间Android,还是在2.x时代. 那个时候搭建开发环境还是挺麻烦的.又是Eclipse,又是ADT的,不同的版本还要安装对应开发包.现在 ...
- python - bilibili(三)wireshark分析
当我们开始打开浏览器,并进入B站直播网页前,我们打开wireshark软件(软件的下载与安装请百度一下)开始截取当前数据. 然后输入直播间网址,enter进入就可以停止截取数据了,然后我们分析所截取的 ...
- 使用Jmeter3.1进行接口测试(包含需登录后测试的接口)
Jmeter版本为3.1,以下只针对此版本进行测试说明: 1.打开Jmeter3.1: 启动命令路径:apache-jmeter-3.1\bin\jmeter.bat 2.测试步骤: 1.测试计划-- ...
- jQuery_第五章_事件和动画
Jquery中的事件与动画 一.window.onload和$(document).read()的细微差别 (1)执行时机 window.onload:所有元素(包括元素的所有关联文件)完全加载到浏览 ...