ZOJ 2866 Overstaffed Company
树状数组
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
using namespace std; const int maxn = + ;
vector<int>Tree[ + ];
int n;
int val[ + ];
int c[maxn];
int ans[ + ]; int lowbit(int x)
{
return x & (-x);
} void Update(int x, int add)
{
while (x < maxn)
{
c[x] += add;
x += lowbit(x);
}
} int Get(int x)
{
int ret = ;
while (x != )
{
ret += c[x];
x -= lowbit(x);
}
return ret;
} void init()
{
for (int i = ; i <= n; i++) Tree[i].clear();
memset(c, , sizeof c);
} void DFS(int now)
{
int A, B;
A = Get( + ) - Get(val[now]);
for (int i = ; i < Tree[now].size(); i++)
DFS(Tree[now][i]);
B = Get( + ) - Get(val[now]);
ans[now] = B - A;
Update(val[now], );
} int main()
{
while (~scanf("%d", &n))
{
init();
for (int i = ; i < n; i++)
{
int k;
scanf("%d", &k);
Tree[k].push_back(i);
}
for (int i = ; i < n; i++)
{
scanf("%d", &val[i]);
val[i]++;
}
DFS();
for (int i = ; i < n; i++)
{
if (i < n - ) printf("%d ", ans[i]);
else printf("%d\n", ans[i]);
}
}
return ;
}
ZOJ 2866 Overstaffed Company的更多相关文章
- ZOJ 2112 Dynamic Rankings(主席树の动态kth)
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2112 The Company Dynamic Rankings ...
- 【转载】图论 500题——主要为hdu/poj/zoj
转自——http://blog.csdn.net/qwe20060514/article/details/8112550 =============================以下是最小生成树+并 ...
- 高级数据结构(树状数组套主席树):ZOJ 2112 Dynamic Rankings
Dynamic Rankings Time Limit: 10 Seconds Memory Limit: 32768 KB The Company Dynamic Rankings has ...
- ZOJ 1542 POJ 1861 Network 网络 最小生成树,求最长边,Kruskal算法
题目连接:problemId=542" target="_blank">ZOJ 1542 POJ 1861 Network 网络 Network Time Limi ...
- ZOJ 3794 Greedy Driver
两次SPFA 第一关找:从1没有出发点到另一个点的多少是留给油箱 把边反过来再找一遍:重每一个点到终点最少须要多少油 Greedy Driver Time Limit: 2 Seconds ...
- ZOJ 2676 Network Wars[01分数规划]
ZOJ Problem Set - 2676 Network Wars Time Limit: 5 Seconds Memory Limit: 32768 KB Special J ...
- ZOJ 2112 Dynamic Rankings (动态第 K 大)(树状数组套主席树)
Dynamic Rankings Time Limit: 10 Seconds Memory Limit: 32768 KB The Company Dynamic Rankings has ...
- ZOJ 2676 Network Wars(最优比例最小割)
Network Wars Time Limit: 5 Seconds Memory Limit: 32768 KB Special Judge Network of Bytelan ...
- ZOJ 2112 Dynamic Rankings(带修改的区间第K大,分块+二分搜索+二分答案)
Dynamic Rankings Time Limit: 10 Seconds Memory Limit: 32768 KB The Company Dynamic Rankings has ...
随机推荐
- ural 1091. Tmutarakan Exams(容斥原理)
1091. Tmutarakan Exams Time limit: 1.0 secondMemory limit: 64 MB University of New Tmutarakan trains ...
- Neutron网络性能测试与分析(一) CVR
测试环境:网络节点运行在Intel(R) Xeon(R) CPU E5-2630 v3服务器上,网卡使用intel的万兆卡82599ES 测试仪使用本人基于dpdk编写的程序,基本上可以打满万兆卡,小 ...
- 实现ie6下的居中
代码如下所示,转自 http://w3help.org/zh-cn/causes/RT8003 对于 text-align 的讨论. <div style="width:200px; ...
- yii2 windows 安装
Yii是一个高性能的,适用于开发WEB2.0应用的PHP框架. Yii自带了丰富的功能 ,包括MVC,DAO/ActiveRecord,I18N/L10N,缓存,身份验证和基于角色的访问控制,脚手架, ...
- 为Android系统内置Java应用程序测试Application Frameworks层的硬件服务
我们在Android系统增加硬件服务的目的是为了让应用层的APP能够通过Java接口来访问硬件服务.那么, APP如何通过Java接口来访问Application Frameworks层提供的硬件服务 ...
- Go-new和make
new返回指向struct的指针,new仅分配内存,而不对对象的值进行初始化 make返回到strcut的对象,而不是指针,只能创建map,slice,channel对象 make([]string, ...
- php - preg_match
任务:匹配一个函数名或者变量名,如果碰到alpha,numeric,_以外的全部不允许通过. 实验1: <?php //第一个字符不符合就直接退出正则匹配 $str = '%abcscript% ...
- Tomcat 7优化
1.在bin/catalina.bat文件中加入下面参数,对JVM进行优化,至于这一大驼参数的作用及说明,大家到网上找找,应该有很多的,如:http://www.mzone.cc/article/32 ...
- Linux(centos5.0+)unison+inotify-tools触发式双向自动同步
192.168.1.11是server1, 192.168.1.22是server2. [1]安装inotify-tools 各大linux发行版本都有inotify-tools软件包,建议通过y ...
- 路由器wan口连接不上的问题
路由器:tp-link:系统:win8.1:网络类型:PPPoE 克隆“当前管理PC的MAC地址”后,无法连接,将网线直接连到电脑上可以连接,所以问题一定出在路由上,经过不断探索发现问题所在,通过命令 ...