AC日记——dispatching bzoj 2809
2809: [Apio2012]dispatching
Time Limit: 10 Sec Memory Limit: 128 MB
Submit: 3290 Solved: 1740
[Submit][Status][Discuss]
Description
Input
Output
Sample Input
0 3 3
1 3 5
2 2 2
1 2 4
2 3 1
Sample Output
HINT
如果我们选择编号为 1的忍者作为管理者并且派遣第三个和第四个忍者,薪水总和为 4,没有超过总预算 4。因为派遣了 2 个忍者并且管理者的领导力为 3,
用户的满意度为 2 ,是可以得到的用户满意度的最大值。
Source
思路:
这题不仅仅是恶心,,简直是个,,,唉,不说了。。
主席树+dfs序;
最后输出的ans是每个忍者可以派遣的忍者的个数*这个忍者的领导力的最大值;
我们思考主席树;
如何用主席树呢?
首先用dfs序跋整个树便利,记录每个点的开始的标号和最后的标号;
然后,我们开始往主席树里加点;
主席树的叶节点是排序离散后的薪水;
主席树维护两个元素,忍者的数量和花费;
然后,我们每次查询就可以了;
细节,,,
要用long long;
查询到末节点的时候,返回值是min(当前预算/当前单个忍者花费,当前忍者数量),不然40分;
来,上代码:
#include <cstdio>
#include <iostream>
#include <algorithm> #define LL long long
#define maxn 100005 using namespace std; struct TreeNodeType {
LL l,r,dis,sum;
};
struct TreeNodeType tree[maxn*]; struct EdgeType {
LL to,next;
};
struct EdgeType edge[maxn<<]; LL if_z,n,m,head[maxn],cost[maxn],lead[maxn];
LL cnt,hash[maxn],root[maxn],tot,start[maxn],end[maxn];
LL ans=,size; char Cget; inline void read_int(LL &now)
{
if_z=,Cget=getchar(),now=;
while(Cget>''||Cget<'')
{
if(Cget=='-') if_z=-;
Cget=getchar();
}
while(Cget>=''&&Cget<='')
{
now=now*+Cget-'';
Cget=getchar();
}
now*=if_z;
} inline void edge_add(LL from,LL to)
{
cnt++;
edge[cnt].to=to;
edge[cnt].next=head[from];
head[from]=cnt;
} void tree_build(LL now,LL l,LL r)
{
if(l==r) return ;
LL mid=(l+r)>>;
tree[now].l=++tot;
tree_build(tree[now].l,l,mid);
tree[now].r=++tot;
tree_build(tree[now].r,mid+,r);
} void tree_add(LL pre,LL now,LL pos,LL l,LL r)
{
tree[now].dis=tree[pre].dis+;
tree[now].sum=tree[pre].sum+hash[pos];
if(l==r) return ;
LL mid=(l+r)>>;
if(pos<=mid)
{
tree[now].l=++tot;
tree_add(tree[pre].l,tree[now].l,pos,l,mid);
tree[now].r=tree[pre].r;
}
else
{
tree[now].r=++tot;
tree_add(tree[pre].r,tree[now].r,pos,mid+,r);
tree[now].l=tree[pre].l;
}
} void Search(LL now,LL fa)
{
start[now]=cnt++,root[cnt]=++tot;
LL pos=lower_bound(hash+,hash+size+,cost[now])-hash;
tree_add(root[cnt-],root[cnt],pos,,size);
for(LL i=head[now];i;i=edge[i].next)
{
if(edge[i].to==fa) continue;
Search(edge[i].to,now);
}
end[now]=cnt;
} LL tree_query(LL pre,LL now,LL pos,LL l,LL r)
{
if(l==r) return min(pos/hash[l],tree[now].dis-tree[pre].dis);
LL pos_=tree[tree[now].l].dis-tree[tree[pre].l].dis;
LL mid=(l+r)>>,dis_=tree[tree[now].l].sum-tree[tree[pre].l].sum;
if(pos<=dis_) return tree_query(tree[pre].l,tree[now].l,pos,l,mid);
else return tree_query(tree[pre].r,tree[now].r,pos-dis_,mid+,r)+pos_;
} int main()
{
read_int(n),read_int(m);
LL bi,master;
for(LL i=;i<=n;i++)
{
read_int(bi),read_int(cost[i]),read_int(lead[i]);
edge_add(bi,i),edge_add(i,bi),hash[i]=cost[i];
if(bi==) master=i;
}
sort(hash+,hash+n+);
size=unique(hash+,hash+n+)-hash-;
root[]=++tot;
tree_build(root[],,size);
cnt=,Search(master,);
for(LL i=;i<=n;i++)
{
LL pos=tree_query(root[start[i]],root[end[i]],m,,size);
ans=max(ans,lead[i]*pos);
}
cout<<ans<<endl;
return ;
}
AC日记——dispatching bzoj 2809的更多相关文章
- AC日记——旅游 bzoj 2157
2157 思路: LCT: 代码: #include <bits/stdc++.h> using namespace std; #define maxn 400005 #define IN ...
- AC日记——codevs1688求逆序对
AC日记--codevs1688求逆序对 锵炬 掭约芴巷 枷锤霍蚣 蟠道初盛 到被他尽情地踩在脚下蹂躏心中就无比的兴奋他是怎么都 ㄥ|囿楣 定要将他剁成肉泥.挫骨扬灰跟随着戴爷这么多年刁梅生 圃鳋 ...
- BZOJ 2809: [Apio2012]dispatching( 平衡树 + 启发式合并 )
枚举树上的每个结点做管理者, 贪心地取其子树中薪水较低的, 算出这个结点为管理者的满意度, 更新答案. 用平衡树+启发式合并, 时间复杂度为O(N log²N) ------------------- ...
- bzoj 2809: [Apio2012]dispatching -- 可并堆
2809: [Apio2012]dispatching Time Limit: 10 Sec Memory Limit: 128 MB Description 在一个忍者的帮派里,一些忍者们被选中派 ...
- 【BZOJ 2809】2809: [Apio2012]dispatching (左偏树)
2809: [Apio2012]dispatching Description 在一个忍者的帮派里,一些忍者们被选中派遣给顾客,然后依据自己的工作获取报偿.在这个帮派里,有一名忍者被称之为 Maste ...
- BZOJ 2809 APIO2012 dispatching Treap+启示式合并 / 可并堆
题目大意:给定一棵树,选定一棵子树中的一些点,薪水和不能超过m,求点的数量*子树根节点的领导能力的最大值 考虑对于每一个节点,我们维护一种数据结构,在当中贪心寻找薪金小的雇佣. 每一个节点暴力重建一定 ...
- BZOJ - 2809 dispatching 主席树+dfs序
在一个忍者的帮派里,一些忍者们被选中派遣给顾客,然后依据自己的工作获取报偿.在这个帮派里,有一名忍者被称之为 Master.除了 Master以外,每名忍者都有且仅有一个上级.为保密,同时增强忍者们的 ...
- BZOJ 2809: [Apio2012]dispatching(左偏树)
http://www.lydsy.com/JudgeOnline/problem.php?id=2809 题意: 思路:最简单的想法就是枚举管理者,在其子树中从薪水低的开始选起,但是每个节点都这样处理 ...
- BZOJ 2809 [Apio2012]dispatching(斜堆+树形DP)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=2809 [题目大意] 给出一棵树,求出每个点有个权值,和一个乘算值,请选取一棵子树, 并 ...
随机推荐
- MySQL数据库主从切换脚本自动化
MySQL数据库主从切换脚本自动化 本文转载自:https://blog.csdn.net/weixin_36135773/article/details/79514507 在一些实际环境中,如何实现 ...
- DeepFaceLab小白入门(1):软件简介!
简介 DeepFaceLab是一种利用深度学习识别和交换图片和视频中的人脸的工具 这是一个github上的开源项目,所有人都可以查看源代码也能免费使用.个人认为这个项目的最大优点就是安装超级简单,几乎 ...
- Aizu - 1386 Starting a Scenic Railroad Service (思维乱搞)
给你n个区间,求: 1:最多有多少区间与同一个区间相交. 2:相交部分的最大区间数目. Sample Input 1 4 1 3 1 3 3 6 3 6 Sample Output 1 2 2 Sam ...
- 线段树:CDOJ1597-An easy problem C(区间更新的线段树)
An easy problem C Time Limit: 4000/2000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others) Pr ...
- hdu 3836 tarjain 求强连通分量个数
// 给你一个有向图,问你最少加几条边能使得该图强连通 #include <iostream> #include <cstdio> #include <cstring&g ...
- Cacti安装脚本Server端+客户端
#!/bin/bash #auto make install LAMP+Cacti #by authors zhang #RRDtool define path variable R_FILES=rr ...
- Learning Deconvolution Network for Semantic Segme小结
题目:Learning Deconvolution Network for Semantic Segmentation 作者:Hyeonwoo Noh, Seunghoon Hong, Bohyung ...
- EOJ Monthly 2018.1
985月赛,当时鸽了,现在想补一补 A. 石头剪刀布的套路 Time limit per test: 1.0 seconds Memory limit: 256 megabytes 现在有一种石头剪刀 ...
- A Few Laughing Men
A Few Laughing Men CodeChef - LAUGHMEN Balaji is a great person to hang out with. He tells really am ...
- iOS UICollectionView高级用法(长按自由移动cell)
iOS 9之后: 示例如下 效果 前言: 看完你可以学到哪些呢? 就是文章标题那么多, 只有那么多. . 手残效果图没弄好. @property (nonatomic, strong) UIColle ...