NOI2010超级钢琴 2
2006: [NOI2010]超级钢琴
Time Limit: 20 Sec Memory Limit: 552 MB
Submit: 1296 Solved: 606
[Submit][Status]
Description
Input
Output
Sample Input
3
2
-6
8
Sample Output
【样例说明】
共有5种不同的超级和弦:
音符1 ~ 2,美妙度为3 + 2 = 5
音符2 ~ 3,美妙度为2 + (-6) = -4
音符3 ~ 4,美妙度为(-6) + 8 = 2
音符1 ~ 3,美妙度为3 + 2 + (-6) = -1
音符2 ~ 4,美妙度为2 + (-6) + 8 = 4
最优方案为:乐曲由和弦1,和弦3,和弦5组成,美妙度为5 + 2 + 4 = 11。
HINT
Source
const maxn=+;inf=maxlongint;
type node=record
x,y,z:longint;
end;
var s,t:array[..,..maxn] of longint;
a,b:array[..maxn] of longint;
i,j,n,m,x,y,k,l,r,tmp:longint;
ans:int64;
c:array[..*maxn] of node;
w:node;
function max(x,y:longint):longint;
begin
if x>y then exit(x) else exit(y);
end; procedure modify(x,y,z:longint);
var k,i:longint;
begin
c[].x:=x;c[].y:=y;c[].z:=z;
i:=;k:=;
while k<=m do
begin
if (k<m) and (c[k+].x>c[k].x) then inc(k);
if c[].x<c[k].x then begin c[i]:=c[k];i:=k;k:=k<<;end
else k:=m+;
end;
c[i]:=c[];
end;
procedure insert(x,y,z:longint);
var k,i:longint;
begin
inc(m);c[].x:=x;c[].y:=y;c[].z:=z;
i:=m;k:=i>>;
while k>= do
begin
if c[].x>c[k].x then begin c[i]:=c[k];i:=k;k:=i>>;end
else k:=;
end;
c[i]:=c[];
end;
procedure sort(l,r:longint);
var i,j,m,temp:longint;
begin
i:=l;j:=r;x:=a[(i+j)>>];
repeat
while b[a[i]]<b[x] do inc(i);
while b[a[j]]>b[x] do dec(j);
if i<=j then
begin
y:=a[i];a[i]:=a[j];a[j]:=y;
inc(i);dec(j);
end;
until i>j;
if i<r then sort(i,r);
if j>l then sort(l,j);
end;
procedure build(h,l,r:longint);
var i,p,mid:longint;
begin
mid:=(l+r)>>;p:=;
for i:=l to r do
if t[h,i]<=mid then
begin
t[h+,l+p]:=t[h,i];
inc(p);
s[h,i]:=p;
end
else
begin
t[h+,mid++i-p-l]:=t[h,i];
s[h,i]:=p;
end;
if l=r then exit;
build(h+,l,mid);
build(h+,mid+,r);
end;
function find(h,l,r,x,y,k:longint):longint;
var ll,rr,mid:longint;
begin
if l=r then exit(t[h,l]);
mid:=(l+r)>>;
if l=x then ll:= else ll:=s[h,x-];rr:=s[h,y]-ll;
if rr>=k then exit(find(h+,l,mid,l+ll,l+rr+ll-,k))
else exit(find(h+,mid+,r,mid++x-l-ll,mid++y-l-rr-ll,k-rr));
end;
procedure init;
begin
readln(n,k,l,r);inc(n);
for i:= to n do begin readln(x);b[i]:=b[i-]+x;end;
for i:= to n do a[i]:=i;
sort(,n);
end;
procedure main;
begin
for i:= to n do t[,a[i]]:=i;
build(,,n);//writeln(n);
for i:=l+ to n do
begin
tmp:=b[a[find(,,n,max(i-r,),i-l,)]];
// writeln(tmp);
insert(b[i]-tmp,i,);
end;
ans:=;
for i:= to k do
begin
w:=c[]; // writeln(w.x);
inc(ans,w.x);
if (w.z>=r-l+) or ((w.y<r+) and (w.z>w.y-l-)) then modify(-inf,inf,inf)
else
begin
tmp:=b[w.y]-b[a[find(,,n,max(w.y-r,),w.y-l,w.z+)]];
modify(tmp,w.y,w.z+);
end;
end;
writeln(ans);
end;
begin
assign(input,'input.txt');assign(output,'output.txt');
reset(input);rewrite(output);
init;
main;
close(input);close(output);
end.
NOI2010超级钢琴 2的更多相关文章
- BZOJ 2006: [NOI2010]超级钢琴
2006: [NOI2010]超级钢琴 Time Limit: 20 Sec Memory Limit: 552 MBSubmit: 2613 Solved: 1297[Submit][Statu ...
- Bzoj 2006: [NOI2010]超级钢琴 堆,ST表
2006: [NOI2010]超级钢琴 Time Limit: 20 Sec Memory Limit: 552 MBSubmit: 2222 Solved: 1082[Submit][Statu ...
- BZOJ 2006: [NOI2010]超级钢琴( RMQ + 堆 )
取最大的K个, 用堆和RMQ来加速... ----------------------------------------------------------------- #include<c ...
- BZOJ_2006_[NOI2010]超级钢琴_贪心+堆+ST表
BZOJ_2006_[NOI2010]超级钢琴_贪心+堆+ST表 Description 小Z是一个小有名气的钢琴家,最近C博士送给了小Z一架超级钢琴,小Z希望能够用这架钢琴创作出世界上最美妙的 音乐 ...
- bzoj2006 [NOI2010]超级钢琴 (及其拓展)
bzoj2006 [NOI2010]超级钢琴 给定一个序列,求长度在 \([L,\ R]\) 之间的区间和的前 \(k\) 大之和 \(n\leq5\times10^5,\ k\leq2\times1 ...
- P2048 [NOI2010]超级钢琴(RMQ+堆+贪心)
P2048 [NOI2010]超级钢琴 区间和--->前缀和做差 多次查询区间和最大--->前缀和RMQ 每次取出最大的区间和--->堆 于是我们设个3元组$(o,l,r)$,表示左 ...
- 洛谷 P2048 [NOI2010]超级钢琴 解题报告
P2048 [NOI2010]超级钢琴 题目描述 小Z是一个小有名气的钢琴家,最近C博士送给了小Z一架超级钢琴,小Z希望能够用这架钢琴创作出世界上最美妙的音乐. 这架超级钢琴可以弹奏出n个音符,编号为 ...
- bzoj千题计划162:bzoj2006: [NOI2010]超级钢琴
http://www.lydsy.com/JudgeOnline/problem.php?id=2006 输出最大的k个 sum[r]-sum[l-1] (L<=r-l+1<=R) 之和 ...
- 【BZOJ 2006】2006: [NOI2010]超级钢琴(RMQ+优先队列)
2006: [NOI2010]超级钢琴 Time Limit: 20 Sec Memory Limit: 552 MBSubmit: 2792 Solved: 1388 Description 小 ...
随机推荐
- 高能物理/HyperPhysics的网站/Website
参考: 基础物理-高能物理[Hyperphysics]
- hdu 1063 Exponentiation (高精度小数乘法)
//大数继续,额,要吐了. Problem Description Problems involving the computation of exact values of very large m ...
- Poj/OpenJudge 1042 Gone Fishing
1.链接地址: http://bailian.openjudge.cn/practice/1042/ http://poj.org/problem?id=1042 2.题目: Gone Fishing ...
- Ext 面向对象程序设计 入门篇
------ 命名空间 定义:对于类的组织定义方式代码: Ext.namespace("Ext.xgao"); ------ 类实例属性 定义:对于一个实例的特征描述代码: Ext ...
- SSH+Ajax实现用户名重复检查(二)
1.另外一种更常用的js表达方式: var user = { inintEvent: function(){ $("input[name='user.User_LogName']" ...
- ajax提交数据Demo
$.ajax({ url: "url", type: "post", data: JSON.stringify(yourData), contentType: ...
- html5新增标签兼容性
很多低版本的浏览器是不识html5新增的标签的,所以为了解决浏览器兼容性问题,主要有两种方法: js可以创建我们自定义的标签,例如,我们可以用js语句 document.createElement(' ...
- php中utf8 与utf-8 与utf8 无BOM
utf8 与utf-8 相信很多程序员刚开始也会有这样的疑惑,如题,我也是. 其实,他们可以这样来区分. 一.在php和html中设置编码,请尽量统一写成“UTF-8”,这才是标准写法,而 ...
- Linux下简易蜂鸣器驱动代码及测试实例
驱动代码: #include <linux/module.h> #include <linux/kernel.h> #include <linux/init.h> ...
- 【Base64】JDK里面实现Base64的API
原文出处: 成熟的毛毛虫的博客 BASE64 编码是一种常用的字符编码,在很多地方都会用到.但base64不是安全领域下的加密解密算法.能起到安全作用的效果很差,而且很容易破解,他核心作用应该是传输数 ...