#SRD0000116. Đỉnh ấn tượng nhất (The Awesomest Vertex)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Đỉnh ấn tượng nhất (The Awesomest Vertex)
The Awesomest Vertex
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
You are given a tree rooted at vertex , containing vertices numbered from to . Vertex has two integers and .
Let consist of every vertex on the path from root to vertex , including both endpoints. Define the awesomeness of by
$$F(v)=\left|\sum_{w\in R(v)}a_w\right|\cdot \left|\sum_{w\in R(v)}b_w\right|.$$Process operations in order:
1 v x: increase by the positive integer , leaving unchanged.2 v: output the maximum awesomeness among all vertices in the subtree rooted at , including itself.
Updates affect all subsequent queries. Absolute values are applied to the two path sums, not separately to the individual vertex values.
Input
- The first line contains integers .
- The second line contains integers , where is the parent of vertex . For , this line is empty.
- The third line contains integers .
- The fourth line contains integers .
- Each of the following lines describes an operation in one of the two formats above.
The condition guarantees a tree rooted at .
Output
For each operation of type 2, print the maximum awesomeness in the requested subtree on its own line, in input order.
The answer may exceed the range of a 32-bit integer, so 64-bit integer arithmetic is required.
Subtasks
- Subtask 1 (10 points): , ; ; initial ; , .
- Subtask 2 (20 points): , ; ; initial ; , .
- Subtask 3 (30 points): , ; ; initial ; , .
- Subtask 4 (40 points): , ; ; initial ; type
1 v xhas , ; type2 vhas .
Examples
Input
5 6
1 1 2 2
10 -3 -7 -3 -10
10 3 9 3 6
2 1
2 2
1 2 6
2 1
1 2 5
2 1
Output
100
91
169
240
Explanation
Initially the pairs of root-path sums are at vertex , at vertex , at vertex , at vertex , and at vertex . Hence ; operations 2 1 and 2 2 yield and .
After 1 2 6, the -path sums at vertices increase by ; their awesomeness becomes , so 2 1 yields . After 1 2 5, vertex has -path sum and -path sum , giving , the maximum over the tree.