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 小 ...
随机推荐
- JSP编程中常用的JavaScript技术(转载)
1.<tronMouseOver=this.style.backgroundColor=’#FFFFFF’ onMouseOut=this.style.backgroundColor=”> ...
- HDU 2993 MAX Average Problem(斜率优化DP)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2993 题目大意:给定一个长度为n(最长为10^5)的正整数序列,求出连续的最短为k的子序列平均值的最大 ...
- 306573704 Char型和string型字符串比较整理(转)
1.赋值 char赋值: char ch1[] = "give me"; char ch2[] = "a cup"; strcpy(ch1,ch2); cout ...
- Linux之最最最最基础(包括在虚拟机中安装linux系统)
这里是以CentOS 6.5 64bit为例(学习用这个,Kali神马的有兴趣自己研究(这个系统是玩渗透用的)) 一 ---->配置Vmware Workstation 自定义--选择 ...
- starling 中 的特效
一. 最好用同一张图片进行缩放变形等处理后组合,这样可以每帧一draw
- iOS中数据库运用之前的准备-简单的数据库
1.数据持久化 数据持久化是通过文件将数据存储在硬盘上 iOS下主要有四种数据持久化方式 属性列表 对象归档 SQLite数据库 CoreData 数据持久化对的对比 1.属性列表.对象归档适合小数据 ...
- 利用Keepalived+mysql构建高可用MySQL双主自动切转
转载:http://www.it300.com/index.php/article-15266.html 关于MySQL-HA,目前有多种解决方案,比如heartbeat.drbd.mmm.共享存储, ...
- Redhat 6.5 x64 下载地址
http://ftp.okhysing.is/ftp/redhat/6.5/isos/x86_64/
- 005.ClearStoredGroups方法
Delphi procedure ClearStoredGroups; 类型:procedure 可见性:protected 所在单元:System.RegularExpressionsCore 父类 ...
- Sersync实时同步企业应用配置实战
一.实验环境 CentOS版本: 6.6(2.6.32.-504.el6.x86_64) Rsync版本: Rsync-3.0.6(系统自带) Sersync版本:sersync2.5.4_64bi ...