当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

5759:Gardener Bo

题目描述
Gardener Bo loves Trees.Now he asks you to help him take care of his lovely tree.

A rooted tree with root=1 is given.Every node on the tree has a value $w_i$.Let $fa[u]$ be the father of $u$.

Let $LCA(u,v)$ be the least common ancestor of $u$ and $v$.The expression $[condition]$ is 1 when $condition$ is True,is 0 when $condition$ is False.

Define

\[f(u)=\sum_{i=1}^n\sum_{j=i}^n(w_i+w_j)*[LCA(i,j)=u]\]

Now there are $Q$ events happening.Each event has one of two types:

$1~u~x$:pick out all $v$ that satisfies $v=u$ or $fa[v]=u$ or $fa[fa[v]]=u$,and add $x$ to $w_v$.

$2~u$:query $f(u)\bmod 2^{32}$.
输入解释
There are several test cases.

The first line contains two integers $n,Q$.

The second line contains $n-1$ integers,i-th indicates $fa[i+1]$.

The third line contains $n$ integers,the i-th indicates the initial $w_i$.

Following $Q$ lines each describes an event.

$1\leq n,Q\leq 3\times 10^5,|w_i|,|x|<10^9$
输出解释
For every event with type 2,you should print a number indicating the answer.
输入样例
5 3
1 1 3 3
-5 2 0 7 -6
1 5 2
2 3
2 2
10 5
1 2 3 3 1 2 6 2 2 
-2 5 8 -6 0 -4 6 6 8 9
2 10
1 3 4
1 6 -2
2 9
2 4
输出样例
6
4
18
16
4294967292
来自杭电HDUOJ的附加信息
Author 绍兴一中
Recommend wange2014

该题目是Virtual Judge题目,来自 杭电HDUOJ

源链接: HDU-5759

最后修改于 2020-10-25T23:25:25+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
16000/8000MS(Java/Others) 131072/131072K(Java/Others)