bzoj2809
可以先穷举那个是管理者,然后就发现
其实就是求每个子树选尽可能多的人,使薪水和小于m
这显然是从小往大选,可以用启发式合并
但是用主席树写的更简单一点吧,dfs序之后
每课线段树不仅维护出现出现个数,然后在维护一个区间和(未离散化之前的)
然后类似查找第k大就可以解决了
type node=record
po,next:longint;
end;
link=record
l,r,s:longint;
sum:int64;
end; var tree:array[..*] of link;
v,a,b,c,e,sa,rank,h,p:array[..] of longint;
w:array[..] of node;
n,m,t,tot,len,x,root,i,s:longint;
ans:int64; function max(a,b:int64):int64;
begin
if a>b then exit(a) else exit(b);
end; procedure swap(var a,b:longint);
var c:longint;
begin
c:=a;
a:=b;
b:=c;
end; procedure sort(l,r: longint);
var i,j,x:longint;
begin
i:=l;
j:=r;
x:=a[(l+r) div ];
repeat
while (a[i]<x) do inc(i);
while (x<a[j]) do dec(j);
if not(i>j) then
begin
swap(a[i],a[j]);
swap(c[i],c[j]);
inc(i);
j:=j-;
end;
until i>j;
if l<j then sort(l,j);
if i<r then sort(i,r);
end; procedure add(x,y:longint);
begin
inc(len);
w[len].po:=y;
w[len].next:=p[x];
p[x]:=len;
end; procedure dfs(x:longint);
var i,y:longint;
begin
i:=p[x];
inc(len);
a[len]:=x;
c[x]:=len;
while i<> do
begin
dfs(w[i].po);
i:=w[i].next;
end;
e[x]:=len;
end; function build(l,r:longint):longint;
var m,q:longint;
begin
inc(t);
if l=r then exit(t)
else begin
q:=t;
m:=(l+r) shr ;
tree[q].l:=build(l,m);
tree[q].r:=build(m+,r);
exit(q);
end;
end; function add(l,r,last,x,y:longint):longint;
var m,q:longint;
begin
inc(t);
if l=r then
begin
tree[t].s:=tree[last].s+;
tree[t].sum:=tree[last].sum+y;
exit(t);
end
else begin
q:=t;
m:=(l+r) shr ;
if x<=m then
begin
tree[q].r:=tree[last].r;
tree[q].l:=add(l,m,tree[last].l,x,y);
end
else begin
tree[q].l:=tree[last].l;
tree[q].r:=add(m+,r,tree[last].r,x,y);
end;
tree[q].sum:=tree[tree[q].l].sum+tree[tree[q].r].sum;
tree[q].s:=tree[tree[q].l].s+tree[tree[q].r].s;
exit(q);
end;
end; function ask(l,r,a,b,k:longint):longint;
var m,s:longint;
p:int64; begin
if l=r then
begin
p:=tree[b].sum-tree[a].sum;
if k>=p then exit(tree[b].s-tree[a].s) //这里要注意下
else exit(k div sa[l]);
end
else begin
m:=(l+r) shr ;
p:=tree[tree[b].l].sum-tree[tree[a].l].sum;
if p>k then
exit(ask(l,m,tree[a].l,tree[b].l,k))
else begin
s:=tree[tree[b].l].s-tree[tree[a].l].s;
exit(s+ask(m+,r,tree[a].r,tree[b].r,k-p));
end;
end;
end; begin
readln(n,m);
for i:= to n do
begin
readln(x,b[i],v[i]);
if x= then root:=i;
add(x,i);
end;
for i:= to n do
begin
a[i]:=b[i];
c[i]:=i;
end;
sort(,n);
tot:=;
rank[c[]]:=;
sa[]:=a[];
for i:= to n do
begin
if a[i]<>a[i-] then
begin
inc(tot);
sa[tot]:=a[i];
end;
rank[c[i]]:=tot;
end;
len:=;
dfs(root);
h[]:=build(,tot);
for i:= to n do
h[i]:=add(,tot,h[i-],rank[a[i]],b[a[i]]);
for i:= to n do
begin
s:=ask(,tot,h[c[i]-],h[e[i]],m);
ans:=max(ans,int64(v[i])*int64(s));
end;
writeln(ans);
end.
bzoj2809的更多相关文章
- BZOJ2809: [Apio2012]dispatching
传送门 主席树经典题. 首先把树搞出来,然后搞出来DFS序.然后离散化点权,在DFS序上建立主席树. 对于每个点对应的区间,查找对应的区间最大的点数即可. //BZOJ2809 //by Cydiat ...
- bzoj1455: 罗马游戏 + bzoj2809: Dispatching(可并堆)
昨天看了可并堆是什么,写的是左偏树 大概就是一棵树 1.有左偏性质,即当前根到左叶子节点距离比到右叶子节点距离大 2.有堆性质,堆顶关键字比子树关键字小 合并两个堆的时候,关键字大的插入到关键字小的那 ...
- 【bzoj2809】 Apio2012—dispatching
http://www.lydsy.com/JudgeOnline/problem.php?id=2809 (题目链接) 题意 给出一棵树,每个节点有两个权值${c}$,${L}$,分别代表花费和领导力 ...
- 左偏树初步 bzoj2809 & bzoj4003
看着百度文库学习了一个. 总的来说,左偏树这个可并堆满足 堆的性质 和 左偏 性质. bzoj2809: [Apio2012]dispatching 把每个忍者先放到节点上,然后从下往上合并,假设到了 ...
- BZOJ2809 [Apio2012]dispatching 可并堆
欢迎访问~原文出处——博客园-zhouzhendong 去博客园看该题解 题目传送门 - BZOJ2809 题意概括 n个点组成一棵树,每个点都有一个领导力和费用,可以让一个点当领导,然后在这个点的子 ...
- 【BZOJ2809】[Apio2012]dispatching 可并堆
[BZOJ2809][Apio2012]dispatching Description 在一个忍者的帮派里,一些忍者们被选中派遣给顾客,然后依据自己的工作获取报偿.在这个帮派里,有一名忍者被称之为 M ...
- BZOJ2809&&LG1552 APIO2012派遣(线段树合并)
BZOJ2809&&LG1552 APIO2012派遣(线段树合并) 题面 自己找去 HINT 简化一题面就是让你从每个点的子树中以\(<=m\)的代价选取尽可能多的点,然后乘上 ...
- BZOJ2809——[Apio2012]dispatching
1.题目大意:给一棵树和M值,每个点有两个权值C和L,选x个点,这x个点的C值的和不能超过M,且这x个点如果都在某个子树内 定义满意度为x*这个子树的根的L值 2.分析:这是一道可并堆的题目,我们考虑 ...
- 【bzoj2809】[Apio2012]dispatching 左偏树
2016-05-31 15:56:57 题目:http://www.lydsy.com/JudgeOnline/problem.php?id=2809 直观的思想是当领导力确定时,尽量选择薪水少的- ...
- 【BZOJ-2809】dispatching派遣 Splay + 启发式合并
2809: [Apio2012]dispatching Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 2334 Solved: 1192[Submi ...
随机推荐
- Bootstrap-全局css样式之按钮
这里所说的按钮只是Bootstrap设计的能使标签或元素呈现按钮样式的属性,所以为 <a>.<button> 或 <input> 元素添加按钮类(button cl ...
- .NET(C#):获取进程的CPU使用状况
第一个是通过手动的方法来计算CPU使用比例:CPU使用比例 = 在间隔时间内进程的CPU使用时间 除以 计算机逻辑CPU数量. 使用Process类的UserProcessorTime和Privile ...
- 【html】【3】html标签列表
必看参考: http://www.divcss5.com/html/h323.shtml http://www.w3school.com.cn/tags/tag_html.asp 常用: <ht ...
- 配置hive元数据库mysql时候出现 Unable to find the JDBC database jar on host : master
解决办法: cd /usr/share/java/,(没有java文件夹,自行创建)rz mysql-connector-java-***.jar,mv mysql-connector-java-* ...
- POJ 2039 To and Fro(模拟)
To and Fro Description Mo and Larry have devised a way of encrypting messages. They first decide sec ...
- 【转】通用分页用户控件(DataGrid,DataList,Repeater都可以用它来分页)
通用分页控件(DataGrid,DataList,Repeater都可以用它来分页) 1.建立用户控件Pager.ascx 1.1 html </ASP:LABEL></TD> ...
- 中文翻译:pjsip文档(四)之ICE Session的使用方法
1:pjsip教程(一)之PJNATH简介 2:pjsip教程(二)之ICE穿越打洞:Interactive Connectivity Establishment简介 3:pjsip教程(三)之ICE ...
- 《paste命令》-linux命令五分钟系列之二十
本原创文章属于<Linux大棚>博客,博客地址为http://roclinux.cn.文章作者为rocrocket. 为了防止某些网站的恶性转载,特在每篇文章前加入此信息,还望读者体谅. ...
- 百度地图API绘制带头箭头的折线
源代码: <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" co ...
- centos 7.0防火墙导致vagrant端口映射失败
在vagrant上部署了centos7.0后,Vagrantfile端口转发设置后,宿主机访问客户机站点还是无法访问,问题出在:centos7.0以上版本默认会安装firewalld防火墙, fire ...