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 ...
随机推荐
- Struts2(一.基本介绍,环境搭建及需求分析)
Struts2框架开发 前言 开发工具:eclipse struts1:老项目使用较多,维护时需要用到 struts2:新项目使用较多 一.特点 1. 无侵入式设计 struts2 与 struts ...
- HashMap 和 HashTable 到底哪不同 ?
HashMap 和 HashTable 到底哪不同 ? 2017/05/29 | 分类: 基础技术 | 1 条评论 | 标签: HASHMAP, HASHTABLE 分享到: 原文出处: 程序员赵鑫 ...
- OpenLDAP介绍
首先LDAP是一个轻量级的产品(LightWeight),是一个Directory(D),存取的协议(Access Protocol). 我要着重指出,LDAP是一个数据库,但是又不是一个数据库.说他 ...
- [kuangbin带你飞]专题一 简单搜索 回顾总结
第二题:bfs,忘了将queue清空. 第三题:bfs,记得使用vis数组,防止重复入队
- LearnPython - Zip格式文件的解压缩
import zipfile import os def unzip(zip_name, target_dir): files = zipfile.ZipFile(zip_name) for zip_ ...
- DotNetOpenAuth Part 1 : Authorization 验证服务实现及关键源码解析
DotNetOpenAuth 是 .Net 环境下OAuth 开源实现框架.基于此,可以方便的实现 OAuth 验证(Authorization)服务.资源(Resource)服务.针对 DotNet ...
- ES6的新特性(19)——Module 的语法
Module 的语法 概述 历史上,JavaScript 一直没有模块(module)体系,无法将一个大程序拆分成互相依赖的小文件,再用简单的方法拼装起来.其他语言都有这项功能,比如 Ruby 的re ...
- PHPDoc 学习记录
https://zh.wikipedia.org/wiki/PHPDoc PHPDoc 是一个 PHP 版的 Javadoc.它是一种注释 PHP 代码的正式标准.它支持通过类似 phpDocumen ...
- excel导出功能原型
本篇博客是记录自己实现的excel导出功能原型,下面我将简单介绍本原型: 这是我自制的窗体,有一个ListView和一个Button(导出)控件. 这是我在网上找到了使用exel需要引用的库. usi ...
- 【最小生成树+LCA】Imperial roads
http://codeforces.com/gym/101889 I 先跑一遍最小生成树,把经过的边和答案记录下来 对于每个询问的边,显然如果处于MST中,答案不变 如果不在MST中,假设这条边连上了 ...