2006: [NOI2010]超级钢琴

Time Limit: 20 Sec  Memory Limit: 552 MB
Submit: 1296  Solved: 606
[Submit][Status]

Description

小Z是一个小有名气的钢琴家,最近C博士送给了小Z一架超级钢琴,小Z希望能够用这架钢琴创作出世界上最美妙的音乐。 这架超级钢琴可以弹奏出n个音符,编号为1至n。第i个音符的美妙度为Ai,其中Ai可正可负。 一个“超级和弦”由若干个编号连续的音符组成,包含的音符个数不少于L且不多于R。我们定义超级和弦的美妙度为其包含的所有音符的美妙度之和。两个超级和弦被认为是相同的,当且仅当这两个超级和弦所包含的音符集合是相同的。 小Z决定创作一首由k个超级和弦组成的乐曲,为了使得乐曲更加动听,小Z要求该乐曲由k个不同的超级和弦组成。我们定义一首乐曲的美妙度为其所包含的所有超级和弦的美妙度之和。小Z想知道他能够创作出来的乐曲美妙度最大值是多少。

Input

第一行包含四个正整数n, k, L, R。其中n为音符的个数,k为乐曲所包含的超级和弦个数,L和R分别是超级和弦所包含音符个数的下限和上限。 接下来n行,每行包含一个整数Ai,表示按编号从小到大每个音符的美妙度。

Output

只有一个整数,表示乐曲美妙度的最大值。

Sample Input

4 3 2 3

3

2

-6

8

Sample Output

11

【样例说明】
共有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的更多相关文章

  1. BZOJ 2006: [NOI2010]超级钢琴

    2006: [NOI2010]超级钢琴 Time Limit: 20 Sec  Memory Limit: 552 MBSubmit: 2613  Solved: 1297[Submit][Statu ...

  2. Bzoj 2006: [NOI2010]超级钢琴 堆,ST表

    2006: [NOI2010]超级钢琴 Time Limit: 20 Sec  Memory Limit: 552 MBSubmit: 2222  Solved: 1082[Submit][Statu ...

  3. BZOJ 2006: [NOI2010]超级钢琴( RMQ + 堆 )

    取最大的K个, 用堆和RMQ来加速... ----------------------------------------------------------------- #include<c ...

  4. BZOJ_2006_[NOI2010]超级钢琴_贪心+堆+ST表

    BZOJ_2006_[NOI2010]超级钢琴_贪心+堆+ST表 Description 小Z是一个小有名气的钢琴家,最近C博士送给了小Z一架超级钢琴,小Z希望能够用这架钢琴创作出世界上最美妙的 音乐 ...

  5. bzoj2006 [NOI2010]超级钢琴 (及其拓展)

    bzoj2006 [NOI2010]超级钢琴 给定一个序列,求长度在 \([L,\ R]\) 之间的区间和的前 \(k\) 大之和 \(n\leq5\times10^5,\ k\leq2\times1 ...

  6. P2048 [NOI2010]超级钢琴(RMQ+堆+贪心)

    P2048 [NOI2010]超级钢琴 区间和--->前缀和做差 多次查询区间和最大--->前缀和RMQ 每次取出最大的区间和--->堆 于是我们设个3元组$(o,l,r)$,表示左 ...

  7. 洛谷 P2048 [NOI2010]超级钢琴 解题报告

    P2048 [NOI2010]超级钢琴 题目描述 小Z是一个小有名气的钢琴家,最近C博士送给了小Z一架超级钢琴,小Z希望能够用这架钢琴创作出世界上最美妙的音乐. 这架超级钢琴可以弹奏出n个音符,编号为 ...

  8. bzoj千题计划162:bzoj2006: [NOI2010]超级钢琴

    http://www.lydsy.com/JudgeOnline/problem.php?id=2006 输出最大的k个 sum[r]-sum[l-1] (L<=r-l+1<=R) 之和 ...

  9. 【BZOJ 2006】2006: [NOI2010]超级钢琴(RMQ+优先队列)

    2006: [NOI2010]超级钢琴 Time Limit: 20 Sec  Memory Limit: 552 MBSubmit: 2792  Solved: 1388 Description 小 ...

随机推荐

  1. poj 3565 uva 1411 Ants KM算法求最小权

    由于涉及到实数,一定,一定不能直接等于,一定,一定加一个误差<0.00001,坑死了…… 有两种事物,不难想到用二分图.这里涉及到一个有趣的问题,这个二分图的完美匹配的最小权值和就是答案.为啥呢 ...

  2. OpenJudge/Poj 2027 No Brainer

    1.链接地址: http://bailian.openjudge.cn/practice/2027 http://poj.org/problem?id=2027 2.题目: 总Time Limit: ...

  3. Eclipse代码自动提示

    发现了一个好用的快捷键,不用跳转到源文件就可以看源代码:先按shift键,然后鼠标点击要看的代码,即可.

  4. VPN client on linux debian

    Install the pptp-linux and pptp-linux-client: sudo apt-get install pptp-linux pptp-linux-client Crea ...

  5. Sublime Text 3的快捷键

    Sublime Text 3是一个非常了不起的软件,它不仅具有令人难以置信的内置功能(多行编辑和VIM模式),而且还支持插件.代码片段和其它许多东西. 今天,我们来总结一下Sublime Text 3 ...

  6. H5 App如此强悍,要降薪的恐怕已不只是iOS程序员

    2015年的最后几天,移动开发圈里最为火爆的话题之一无疑是“iOS程序员月薪降至12K”这则报道. 有人认为这是O2O创业遇冷所致,也有人认为这是iOS生态过于封闭致使智能硬件等新领域对iOS开发者的 ...

  7. 博客迁移到www.imyzf.com

    本博客已经迁移到www.imyzf.com,本站不再更新,请谅解!

  8. Control character in cookie value, consider BASE64 encoding your value , java操作cookie遇到中文会报错的解决方案

    项目当中用到cookie保存中文,但是会报如下错误: Control character in cookie value, consider BASE64 encoding your value 大概 ...

  9. python AES 加密与解密

    #用aes加密,再用base64 encode def aes_encrypt(data): from Crypto.Cipher import AES import base64 key=setti ...

  10. 使用grub硬盘重装ubuntu

    电脑一直是双系统,Windows8 + Ubuntu13.04,昨天瞎搞,更新了一下QT,结果就不能开机了...真心难. 老系统坏了也好,正好可以装个Ubuntu14.04LTS.手边没有U盘,可以把 ...