#SGM0000084. Bạn có trả lời được các truy vấn VII (Can you answer these queries VII)
Bạn có trả lời được các truy vấn VII (Can you answer these queries VII)
Can you answer these queries VII
Source: SPOJ
Version: Phuoc Hung OJ Extended
Problem
Each vertex of a tree stores an integer. Support assigning one value to every vertex on a path and querying the maximum contiguous subarray sum along a path. The empty subarray is allowed, so the answer is never negative.
Input
The first line contains . The second line contains the initial values. The next lines contain the tree edges. The next line contains . Each of the following operations is:
1 a b: query the maximum contiguous subarray sum on the path from to .2 a b c: assign value to every vertex on the path from to .
Output
For each operation of type 1, print the requested maximum subarray sum.
Subtasks
Subtask 1 (20%)
- The tree size and number of operations are at most 20.
- All other conditions are the same as Subtask 3.
Subtask 2 (30%)
- The tree size and number of operations are at most 2000.
- All other conditions are the same as Subtask 3.
Subtask 3 (50%)
- .
- .
Example
Input
1
2
5
1 1 1
1 1 1
2 1 1 18
2 1 1 -16
2 1 1 9
Output
2
2
Explanation
The first two operations are path queries and both see the initial value 2. The remaining operations only assign new values and therefore produce no output.