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

建议使用的浏览器:

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

6663:Andy and Data Structure

题目描述
Andy is a famous data structure expert at Nanjing University second to none. One day he throws a plain dry data structure problem to his friends, but none of them can solve. How about you?

Given a tree rooted at node 1. Each node has a weight which is 0 initially. Define the distance between two nodes as the number of edges in the unique simple path between the two nodes. You need to perform these two types of operations:

- Type 1: given $a, x, y, z$, add $z$ to the weights of all $a$'s descendants (including $a$ itself) whose distances to $a$ are $y$ modulo $x$;
- Type 2: given $a$, return the weight of node $a$.
输入解释
The first line of the input is a single integer $T$ $(1 \leq T \leq 4)$, the number of test cases.

Each test cases starts with two integers $n, m$ $(1 \leq n, m \leq 300000)$, denoting that there are $n$ nodes (numbered $1$ through $n$) in the tree and you need to perform $m$ operations. The next line contains $n-1$ integers, $f_1, f_2, \cdots, f_{n-1}$ $(1 \leq f_i \leq i)$, specifying the edges of the trees; the $i$th integer denotes the parent of node $i+1$. The next $m$ lines describe the operations. Each line is either $\texttt{1 a x y z}$ $(1 \leq a \leq n, 1 \leq x \leq n, 0 \leq y < x, 0 \leq z \leq 500)$, denoting an operation of type 1, or $\texttt{2 a}$ $(1 \leq a \leq n)$, denoting an operation of type 2.
输出解释
For each operation of type 2 in each test case, print the answer in one line.
输入样例
1
5 5
1 1 2 1
1 1 5 4 1
1 1 4 1 5
1 2 1 0 4
2 3
2 1
输出样例
5
0
来自杭电HDUOJ的附加信息
Recommend chendu

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

源链接: HDU-6663

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

共提交 0

通过率 --%
时间上限 内存上限
20000/20000MS(Java/Others) 524288/524288K(Java/Others)