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 [题目大意] 给出一棵树,求出每个点有个权值,和一个乘算值,请选取一棵子树, 并 ...
随机推荐
- 04Windows中的字符类型
1. Windows 中常用的数据类型定义 //WinNt.h中定义 typedef unsigned short wchar_t; //A 16-bit character typedef char ...
- Hogan的安装和使用
Hogan的安装和使用 通过npm安装hogan: npm install hogan.js --save-dev CommonJs下的使用方式: // 引入hogan var hogan = req ...
- 我的Python分析成长之路6
模块:本质就是.py结尾的文件.从逻辑上组织python代码. 包: 本质就是一个目录,带有__init__.py文件,从逻辑上组织模块. 模块的分类: 1.标准库(内置的模块) 2.开源库(第三方库 ...
- 使用TensorFlow的卷积神经网络识别手写数字(1)-预处理篇
功能: 将文件夹下的20*20像素黑白图片,根据重心位置绘制到28*28图片上,然后保存.经过预处理的图片有利于数字的准确识别.参见MNIST对图片的要求. 此处可下载已处理好的图片: https:/ ...
- 中移物联网onenet入门学习笔记1:资料获取
onenet学习资料.视频.例程汇总:https://open.iot.10086.cn/bbs/thread-977-1-1.html onenet开发文档:https://open.iot.100 ...
- 创建Django项目并将其部署在腾讯云上
这段时间在做scrapy爬虫,对爬出来的数据基于Django做了统计与可视化,本想部署在腾讯云上玩玩,但是因为以前没有经验遇到了一些问题,在这里记录一下: 首先说下Django的创建与配置: 1. 创 ...
- (转)webView清除缓存
NSURLCache * cache = [NSURLCache sharedURLCache]; [cache removeAllCachedResponses]; [cache setDiskCa ...
- stm32L0系列学习(一)
开发用到的具体芯片是stm32L011F3 stm32L0总体特性,定位: 可见容量是比较少的,功耗很低,adc12位,7种低功耗模式 jlink和sdk的引脚关系图: HAL的库框图 官方给出的HA ...
- Aizu 2450 Do use segment tree 树链剖分
题意: 给出一棵\(n(1 \leq n \leq 200000)\)个节点的树,每个节点有一个权值. 然后有\(2\)种操作: \(1 \, a \, b \, c\):将路径\(a \to b\) ...
- Python 开启线程的2中方式,线程VS进程(守护线程、互斥锁)
知识点一: 进程:资源单位 线程:才是CPU的执行单位 进程的运行: 开一个进程就意味着开一个内存空间,存数据用,产生的数据往里面丢 线程的运行: 代码的运行过程就相当于运行了一个线程 辅助理解:一座 ...