二分+dfs序+前缀和+瞎几把yy

#include "a.h"

int n;
aLL a;
struct edge
{
int to, nx, w;
} e[N << ];
arr fi;
int ce = ;
aLL sum, ans;
aLL vec, up, down, res;
ll tot = ;
ll rs = ; inline void add(int u, int v, int w)
{
e[++ce] = edge{v, fi[u], w};
fi[u] = ce;
} void dfs(int x)
{
if (fi[x] == -)
{
rs = res[x];
rs += up[x], rs -= down[x];
ans[x] = rs;
return;
}
for (int i = fi[x]; i != -; i = e[i].nx)
{
int v = e[i].to, w = e[i].w;
sum[++tot] = sum[tot - ] + w;
int p = lower_bound(sum + , sum + + tot, sum[tot] - a[v]) - sum;
if (tot - >= p)
up[vec[tot - ]]++, down[vec[p - ]]++;
vec[tot] = v;
dfs(v);
tot--;
res[x] += rs;
rs = ;
}
rs = res[x];
rs += up[x], rs -= down[x];
ans[x] = rs;
} int main()
{
// file("test");
while (~scanf("%d", &n))
{
me(fi, -);
For(i, , n) sdf(a[i]);
For(i, , n)
{
int x, y;
sdf(x), sdf(y);
add(x, i, y);
}
vec[] = ;
sum[] = ;
dfs();
For(i, , n)
printf("%d ", ans[i]);
}
return ;
}

B. Alyona and a tree的更多相关文章

  1. Codeforces Round #381 (Div. 2)D. Alyona and a tree(树+二分+dfs)

    D. Alyona and a tree Problem Description: Alyona has a tree with n vertices. The root of the tree is ...

  2. codeforces 381 D Alyona and a tree(倍增)(前缀数组)

    Alyona and a tree time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

  3. Codeforces Round #381 (Div. 1) B. Alyona and a tree dfs序 二分 前缀和

    B. Alyona and a tree 题目连接: http://codeforces.com/contest/739/problem/B Description Alyona has a tree ...

  4. Codeforces Round #381 (Div. 2) D. Alyona and a tree 树上二分+前缀和思想

    题目链接: http://codeforces.com/contest/740/problem/D D. Alyona and a tree time limit per test2 secondsm ...

  5. CodeForces 682C Alyona and the Tree (树+dfs)

    Alyona and the Tree 题目链接: http://acm.hust.edu.cn/vjudge/contest/121333#problem/C Description Alyona ...

  6. Alyona and a tree

    Alyona and a tree time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

  7. Codeforces Round #358 (Div. 2) C. Alyona and the Tree 水题

    C. Alyona and the Tree 题目连接: http://www.codeforces.com/contest/682/problem/C Description Alyona deci ...

  8. Codeforces Round #381 (Div. 2) D. Alyona and a tree dfs序+树状数组

    D. Alyona and a tree time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

  9. Codeforces Round #358 (Div. 2) C. Alyona and the Tree dfs

    C. Alyona and the Tree time limit per test 1 second memory limit per test 256 megabytes input standa ...

  10. XJOI 3363 树4/ Codeforces 739B Alyona and a tree(树上差分+路径倍增)

    D. Alyona and a tree time limit per test  2 seconds memory limit per test  256 megabytes input  stan ...

随机推荐

  1. 如何获取view的大小

    很多初学者都会犯一个错误 ,就是在onCreate或者onStart里面去获取view的大小,然而这样获取到的宽高通常都是0,为什么呢?因为view的测量过程和activity的生命周期不是同步的,因 ...

  2. uni-app 父组件引用子组件时怎么调用子组件的方法

    1.写一个简单的子组件main/index.vue: <template> <view> </view> </template> <script& ...

  3. [译]在Linux上的提高MySQL/MariaDB安全性的12条建议

    MySQL 是世界上最流行的开源数据库系统,而MariaDB(MySQL的一个分支)是世界上发展最快的开源数据库系统.安装MySQL服务器之后,它的默认配置是不安全的,保护它是一般数据库管理中的基本任 ...

  4. Linux16.04 LTS 环境下将cmake的项目转换成eclipse可导入可调试的工程项目

    Linux作为一个开源系统,其中的一个优势就是有效的将各种源码编译得到的库集合在一起,为项目的使用创建了便捷.通常情况下,我们在开发自己的开源项目时,喜欢使用cmake调用各种三方库,如opencv ...

  5. Linux下Wheel用户组介绍

    昨天遇到一个很奇怪的事情,有一台服务器在使用su - root命令切换到root账号时,老是报密码不正确.但是root密码完全是正确的,而且可以使用账号密码直接ssh登录服务器.很是纳闷,如下所示: ...

  6. SQL Server如何用触发器捕获DML操作的会话信息

    需求背景 上周遇到了这样一个需求,维护人员发现一个表的数据经常被修改,由于历史原因:文档缺少:以及维护人员的经常变更,导致他们对系统也业务也不完全熟悉,他们也不完全清楚哪些系统和应用程序会对这个表的数 ...

  7. Windows Server 2016-Active Directory域服务端口汇总

    本章为大家简单整理一下有关Windows server Active Directory和Active Directory域服务(AD DS)组件的端口要求.生产环境中我们在做网络调整.防火墙或者开关 ...

  8. 【2018.05.09 Python学习及实践】个人项目中使用的Python库备忘-持续更新

    科研中无论是使用C/C++.Python.Matlab,如果能找到合适的库可谓是事半功倍: 有时候忙活半天才发现本身就有成熟的库可用,自己实现的在功能.性能.安全性上都远远不及,虽然锻炼了能力,但存在 ...

  9. 我为什么要写 blog?

    从事软件测试工作10余年,也没在网上留下些什么.最近忙着找工作,年龄上又遇到了瓶颈,发现好多工作岗位需要技术博客,正好趁这个机会,梳理一下自己的知识点,记录下来和大家一起学习探讨,共同进步.欢迎加我微 ...

  10. 删除排序链表中的重复元素的golang实现

    给定一个排序链表,删除所有重复的元素,使得每个元素只出现一次. 输入: ->-> 输出: -> 输入: ->->->-> 输出: ->-> 我们先 ...