2016-2017 ACM-ICPC Southwestern European Regional Programming Contest (SWERC 2016) F dfs序+树状数组
Performance Review
Employee performance reviews are a necessary evil in any company. In a performance review, employees give written feedback about each other on the work done recently. This feedback is passed up to their managers which then decide promotions based on the feedback received. Maria is in charge of the performance review system in the engineering division of a famous company. The division follows a typical structure. Each employee (except the engineering director) reports to one manager and every employee reports directly or indirectly to the director. Having the managers assessing the performance of their direct reports has not worked very well. After thorough research, Maria came up with a new performance review system. The main idea is to complement the existing corporate structure with a technical rank for each employee. An employee should give feedback only about subordinates with lower technical level. Hence, the performance review will work as follows. Employees prepare a summary of their work, estimate how much time it takes to review it, and then request their superiors with higher technical rank to review their work. Maria is very proud of this new system, but she is unsure if it will be feasible in practice. She wonders how much time each employee will waste writing reviews. Can you help her out?
Task
Given the corporate structure of the engineering division, determine how much time each employee will spend writing performance reviews.
Input
The rst line of input has one integer E, the number of employees, who are conveniently numbered between 1 and E. The next E lines describe all the employees, starting at employee 1 until employee E. Each line contains three space-separated integers mi ri ti, the manager, the technical rank and the expected time to perform the review of employee i. The engineering director has no manager, represented with mi = −1. The other employees have mi between 1 and E.
SWERC'2016 Universidade do Porto 13
Problem F Problem F
Constraints 1 ≤ E ≤ 100000 Number of employees 1 ≤ ri ≤ 100000 Technical rank of each employee 1 ≤ ti ≤ 100000 Expected time to perform each review
Output
The output contains E lines. Line i has the time employee i will spend writing reviews.
Sample Input
5
4 4 80
1 1 40
-1 10 60
3 5 50
4 8 70
Sample Output
40
0
240
120
0
题意:给你一棵树 每个结点有r,t值 现在求所有结点i的子树中的r值小于i点的r值的所有结点的t值之和
题解:dfs序列+树状数组 结点按照r值排序 r值相同的深度小的排前面。依次处理结点 ,将子树的操作转换到区间上。树状数组中存的是结点序号(dfs遍历序号in[root])
#include<bits/stdc++.h>
using namespace std;
#define ll __int64
#pragma comment(linker, "/STACK:102400000,102400000")
ll n;
ll a,b,c;
ll pre[];
ll in[];
ll out[];
ll nedge=;
ll dfn=;
ll dep[];
map<ll,ll>mp;
struct node
{
ll pre;
ll to;
}N[*];
struct dian
{
ll w;
ll you;
ll id;
}M[],MM[];
ll tree[];
bool cmp(struct dian aaa,struct dian bbb)
{
if(aaa.you<bbb.you)
return true;
else
{
if(aaa.you==bbb.you)
return dep[in[aaa.id]]<dep[in[bbb.id]];
}
return false;
}
void add(ll from,ll to)
{
nedge++;
N[nedge].to=to;
N[nedge].pre=pre[from];
pre[from]=nedge;
}
void getdfs(ll root,int de)
{
in[root]=++dfn;
MM[dfn]=M[root];
dep[dfn]=de;
mp[root]=;
for(ll i=pre[root];i;i=N[i].pre){
if(mp[N[i].to])
continue;
getdfs(N[i].to,de+);
}
out[root]=dfn;
}
ll lowbit(ll xx)
{
return xx&(-xx);
}
void add2 (ll x,ll y)
{
for(ll i=x;i<=n;i+=lowbit(i))
tree[i]+=y;
}
ll getsum (ll x)
{
ll ans=;
for(ll i=x;i>=;i-=lowbit(i))
ans+=tree[i];
return ans;
}
int main()
{
scanf("%I64d",&n);
memset(tree,,sizeof(tree));
memset(pre,,sizeof(pre));
nedge=;
ll ro=;
for(ll i=;i<=n;i++)
{
scanf("%I64d %I64d %I64d",&a,&b,&c);
M[i].w=c;
M[i].you=b;
M[i].id=i;
if(a==-){
ro=i;
continue;
}
add(a,i);
add(i,a);
}
getdfs(ro,);
ll ans[];
sort(MM+,MM++n,cmp);
for(ll i=;i<=n;i++)
{
ll l,r;
l=in[MM[i].id];
r=out[MM[i].id];
ans[MM[i].id]=getsum(r)-getsum(l);
add2(l,MM[i].w);
}
for(ll i=;i<=n;i++)
printf("%I64d\n",ans[i]);
return ;
}
2016-2017 ACM-ICPC Southwestern European Regional Programming Contest (SWERC 2016) F dfs序+树状数组的更多相关文章
- Gym 2009-2010 ACM ICPC Southwestern European Regional Programming Contest (SWERC 2009) A. Trick or Treat (三分)
题意:在二维坐标轴上给你一堆点,在x轴上找一个点,使得该点到其他点的最大距离最小. 题解:随便找几个点画个图,不难发现,答案具有凹凸性,有极小值,所以我们直接三分来找即可. 代码: int n; lo ...
- 2016-2017 ACM-ICPC Southwestern European Regional Programming Contest (SWERC 2016)
A. Within Arm's Reach 留坑. B. Bribing Eve 枚举经过$1$号点的所有直线,统计直线右侧的点数,旋转卡壳即可. 时间复杂度$O(n\log n)$. #includ ...
- 2016-2017 ACM-ICPC Southwestern European Regional Programming Contest (SWERC 2016) B - Bribing Eve
地址:http://codeforces.com/gym/101174/attachments 题目:pdf,略 思路: 把每个人的(x1,x2)抽象成点(xi,yi). 当1号比i号排名高时有==& ...
- 2016-2017 ACM-ICPC Southwestern European Regional Programming Contest (SWERC 2016) D.Dinner Bet 概率DP+排列组合
题目链接:点这里 题意: 1~N标号的球 现在A有C个,B有C个 每次可以随机得到D个不同的球(1~N);问你A或B中的C个球都出现一次的 期望次数 题解: dp[i][j][k]表示 随机出现了i个 ...
- 2016-2017 ACM-ICPC Southwestern European Regional Programming Contest (SWERC 2016) E.Passwords AC自动机+dp
题目链接:点这里 题意: 让你构造一个长度范围在[A,B]之间 字符串(大小写字母,数字),问你有多少种方案 需要满足条件一下: 1:构成串中至少包含一个数字,一个大写字母,一个小写字母: 2:不 ...
- 2017-2018 ACM-ICPC Southwestern European Regional Programming Contest (SWERC 2017)
A. Cakey McCakeFace 按题意模拟即可. #include<stdio.h> #include<iostream> #include<string.h&g ...
- 2016-2017 ACM-ICPC Northwestern European Regional Programming Contest (NWERC 2016)
A. Arranging Hat $f[i][j]$表示保证前$i$个数字有序,修改了$j$次时第$i$个数字的最小值. 时间复杂度$O(n^3m)$. #include <bits/stdc+ ...
- 2016-2017 ACM-ICPC Southeastern European Regional Programming Contest (SEERC 2016)
题目链接 Codefores_Gym_101164 Solved 6/11 Penalty Problem A Problem B Problem C Problem D Problem E Pr ...
- 2017 ACM-ICPC, Universidad Nacional de Colombia Programming Contest K - Random Numbers (dfs序 线段树+数论)
Tamref love random numbers, but he hates recurrent relations, Tamref thinks that mainstream random g ...
随机推荐
- Linux安装JDK8详细步骤
1.下载jdk8 查看Linux位数,到oracle官网下载对应的jdk ① sudo uname --m 确认32位还是64位 ② https://www.oracle.com/technetwo ...
- Spring框架 之IOC容器 和AOP详解
主要分析点: 一.Spring开源框架的简介 二.Spring下IOC容器和DI(依赖注入Dependency injection) 三.Spring下面向切面编程(AOP)和事务管理配置 一.S ...
- PHPCMS如何让手机站点取消浏览大图直接加载原图
一.然后找到phpcms\modules\wap\functions\global.func.php 文件,找到相关代码,如下图: return '<img src="'.thumb( ...
- js判断PC端 移动端 并跳转到对应页面
一.PC端跳转到移动端 html页面: <script>var webroot="/",catid="{$catid}",murl="m/ ...
- Java Monitoring&Troubleshooting Tools
JDK Tools and Utilities Monitoring Tools You can use the following tools to monitor JVM performance ...
- 【第七章】MySQL数据库备份-物理备份
一.数据库备份 备份的目的: 备份: 能够防止由于机械故障以及人为误操作带来的数据丢失,例如将数据库文件保存在了其它地方. 冗余: 数据有多份冗余,但不等备份,只能防止机械故障还来的数据丢失,例如主备 ...
- Debian 给非 ROOT 用户添加 sudoer 权限
问题描述 从官方镜像安装的 Debian 9 (Stretch)比较纯净,但因此需要自己安装.配置许多常用的 Linux 应用,这里就需要 sudo (super user do)临时获取 root ...
- 用 Python 编写的 Python 解释器
Allison是Dropbox的工程师,在那里她维护着世界上最大的由Python客户组成的网络.在Dropbox之前,她是Recurse Center的引导师, … 她在北美的PyCon做过关于Pyt ...
- ES6的新特性(15)——Promise 对象
Promise 对象 Promise 的含义 Promise 是异步编程的一种解决方案,比传统的解决方案——回调函数和事件——更合理和更强大.它由社区最早提出和实现,ES6 将其写进了语言标准,统一了 ...
- 针对某一网站的UI进行分析
本周课上教学通过对PM(项目经理)的学习,我了解到PM 对项目所有功能的把握, 特别是有关的UI内容.最差的UI, 体现了团队的组织架构:其次, 体现了产品的内部结构:最好, 体现了用户的自然需求. ...