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序+树状数组的更多相关文章

  1. Gym 2009-2010 ACM ICPC Southwestern European Regional Programming Contest (SWERC 2009) A. Trick or Treat (三分)

    题意:在二维坐标轴上给你一堆点,在x轴上找一个点,使得该点到其他点的最大距离最小. 题解:随便找几个点画个图,不难发现,答案具有凹凸性,有极小值,所以我们直接三分来找即可. 代码: int n; lo ...

  2. 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 ...

  3. 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号排名高时有==& ...

  4. 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个 ...

  5. 2016-2017 ACM-ICPC Southwestern European Regional Programming Contest (SWERC 2016) E.Passwords AC自动机+dp

    题目链接:点这里 题意: 让你构造一个长度范围在[A,B]之间 字符串(大小写字母,数字),问你有多少种方案 需要满足条件一下: 1:构成串中至少包含一个数字,一个大写字母,一个小写字母:   2:不 ...

  6. 2017-2018 ACM-ICPC Southwestern European Regional Programming Contest (SWERC 2017)

    A. Cakey McCakeFace 按题意模拟即可. #include<stdio.h> #include<iostream> #include<string.h&g ...

  7. 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+ ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. spring cloud 入门系列七:基于Git存储的分布式配置中心--Spring Cloud Config

    我们前面接触到的spring cloud组件都是基于Netflix的组件进行实现的,这次我们来看下spring cloud 团队自己创建的一个全新项目:Spring Cloud Config.它用来为 ...

  2. 存储过程关于LOOP循环问题

    本随笔文章,由个人博客(鸟不拉屎)转移至博客园 发布时间: 2018 年 10 月 17 日 原地址:https://niaobulashi.com/archives/procedures_loop. ...

  3. 136.只出现一次的数字 leetcode ^运算符 JavaScript解法

    leetcode上的一道题简单题 给定一个非空整数数组,除了某个元素只出现一次以外,其余每个元素均出现两次.找出那个只出现了一次的元素. 说明: 你的算法应该具有线性时间复杂度. 你可以不使用额外空间 ...

  4. centos7.2部署docker-17.06.0-ce的bug:Error response from daemon: oci runtime error: container_linux.go:262: starting container process caused "process_linux.go:339: container init caused \"\"".

    现象: 操作系统:centos 7.2 kernel 3.10.0-327.el7.x86_64 mesos:1.3.0 docker:docker-17.06.0-ce 在做mesos验证时,通过m ...

  5. RC电路简介,RC串并联电路的工作原理及应用

    RC电路简介,RC串并联电路的工作原理及应用 RC电路全称Resistance-Capacitance Circuits.一个 相移电路(RC电路)或称 RC滤波器. RC网络, 是一个包含利用电压源 ...

  6. [leetcode-811-Subdomain Visit Count]

    A website domain like "discuss.leetcode.com" consists of various subdomains. At the top le ...

  7. eFPGA与FPGA SoC,谁将引领下一代可编程硬件之潮流?|半导体行业观察

    eFPGA:冉冉升起的新星 eFPGA即嵌入式FPGA(embedded FPGA),是近期兴起的新型电路IP. 随着摩尔定律越来越接近瓶颈,制造ASIC芯片的成本越来越高.因此,设计者会希望ASIC ...

  8. 每日Scrum--No.2

    Yesterday:找地图 Today: 找到最适合我们软件的地图版本 Problem:找不到特别匹配的版本

  9. CS小分队第二阶段冲刺站立会议(5月30日)

    昨日成果:解决了前天遗留的问题,实现了主界面对于电脑上应用的添加和删除 遇到问题:添加和删除按钮时候,按钮位置图像与北京图片冲突,会出现闪动现象. 删除是通过右键单击出现菜单,其中有删除的选项,但是这 ...

  10. 【线段树求区间第一个不大于val的值】Lpl and Energy-saving Lamps

    https://nanti.jisuanke.com/t/30996 线段树维护区间最小值,查询的时候优先向左走,如果左边已经找到了,就不用再往右了. 一个房间装满则把权值标记为INF,模拟一遍,注意 ...