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 ...
随机推荐
- java 百分比显示
DecimalFormat percent = new DecimalFormat("0.00%"); completed_num = (double) involvedTask_ ...
- <>跟!=
这两个是没有区别的,都是不等于
- PHP 数组转字符串,与字符串转数组
implode 使用一个字符串将数组变成字符串 <?php $array = array('lastname', 'email', 'phone'); $comma_separated = im ...
- SqlSugar-执行Sql语句查询实例
使用SqlSugar执行sql语句 1.简单查询 SqlSugarClient db = SugarContext.GetInstance(); //执行sql语句,处理 //1.执行sql,转成li ...
- LINQ数据库连接对象制造工厂
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.D ...
- Android eclipse - aapt.exe has stopped working.
今天在修改Android的布局文件的时候,发现每保存一次,就提示: aapt.exe has stopped working(appt.exe已停止工作).很是郁闷,当时Android控制台已经提示错 ...
- This 在 C# 中的含义
这涉及到c# 中的oo思想,其实不管在c# 或其他编码语言中,很多抽象的概念当你项目经验多了,自然而然就会对这些东西理解的更透彻点,更加具象. 这里有一些面向对象编程的概念需要说明:类(Class)的 ...
- 拥抱模块化的JavaScript
前言 我们再一次被计算机的名词.概念笼罩. Backbone.Emberjs.Spinejs.Batmanjs 等MVC框架侵袭而来.CommonJS.AMD.NodeJS.RequireJS.Sea ...
- bootstrap 下 标签页跳转总结
最近遇到一个问题,是关于bootstrap中的标签页实现上的一些功能实现,现总结一下. 问题描述:点击其他标签页后,如何在点击搜索按钮后自动跳转到第一个标签页.如下图 通过对bootstrap框架里的 ...
- 【python】闰年规则
公历闰年判定遵循的规律为: 四年一闰,百年不闰,四百年再闰. 公历闰年的简单计算方法(符合以下条件之一的年份即为闰年)1.能被4整除而不能被100整除.2.能被400整除.