#P11025. [2016杭电多校]Gardener Bo
[2016杭电多校]Gardener Bo
Gardener Bo
Problem Description
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 .Let be the father of . Let be the least common ancestor of and .The expression is 1 when is True,is 0 when is False. Define [f(u)=\sum_{i=1}^n\sum_{j=i}^n(w_i+w_j)*[LCA(i,j)=u]] Now there are events happening.Each event has one of two types: :pick out all that satisfies or or ,and add to . :query .
Input
There are several test cases. The first line contains two integers . The second line contains integers,i-th indicates . The third line contains integers,the i-th indicates the initial . Following lines each describes an event.
Output
For every event with type 2,you should print a number indicating the answer.
Sample Input
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
Sample Output
6
4
18
16
4294967292
Author
绍兴一中
Source
2016 Multi-University Training Contest 3