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 ;
}

最新文章

  1. Win7快速启动栏
  2. 下载https协议需要的cer证书
  3. PHP跳转页面的几种实现方法详解
  4. phpcms图片模型调用组图的问题
  5. 两个img之间出现间隙的解决方法
  6. search--搜索引擎的使用笔记
  7. JNDI学习总结(一)——JNDI数据源的配置
  8. laravel md5+salt 密码
  9. JS引用类型之——RegExp
  10. Visual Studio Code 与 Github 集成
  11. 【淡墨Unity3D Shader计划】五 圣诞用品: Unity在Shader三种形式的控制&amp;amp;混合操作编译
  12. 较简单的用ajax修改和添加功能(链接数据库)
  13. struts2 内容记录
  14. JQuery插件的写法和规范
  15. HFile
  16. 嵌入式linux——S3C2440介绍(二)
  17. mysql数据库优化之 如何选择合适的列建立索引
  18. java输入最大10位数,倒数输出(很鸡肋)
  19. idea取消参数名称(形参名)提示
  20. Python序列结构--列表(一)

热门文章

  1. leetcode-每个节点的右向指针(填充同一层的兄弟节点)
  2. 【python 3.6】python读取json数据存入MySQL(二)
  3. day04 list tuple (补)
  4. Python最简编码规范
  5. presto——java.sql.SQLException: Error executing query与javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?异常问题
  6. spark-local-运行异常-Could not locate executable null\bin\winutils.exe in the Hadoop binaries
  7. B. Counting-out Rhyme(约瑟夫环)
  8. Scrum立会报告+燃尽图(十一月十九日总第二十七次):功能开发与修复上一阶段bug
  9. AOP:静态代理实现方式①通过继承②通过接口
  10. Beta版冲刺前准备