After having lots of fun dealing with arithmetic sequences and squares, you decided to try combining arithmetic sequences and subtrees!
You are given a tree with
Let
You are asked to perform
Input Format | Description |
---|---|
UPDATE u a b c |
For all vertices |
QUERY u a b |
Output the sum of the values of all vertices |
Constraints
For this problem, you will NOT be required to pass all the samples in order to receive points. In addition, all subtasks are disjoint, and you are NOT required to pass previous subtasks to earn points for a specific subtask.
Subtask | Points | Additional Constraints | |
---|---|---|---|
None | |||
None |
For all subtasks:
Input Specification
The first line contains 2 integers,
The next line contains
The next
Output Specification
This problem is graded with an identical
checker. This includes whitespace characters. Ensure that every line of output is terminated with a \n
character and that there are no trailing spaces.
For each QUERY
operation, output the answer on its own line. If there are no vertices that meet the query parameters, then the answer is
Sample Input 1
5 4
0 1 1 3
UPDATE 0 1 2 397
QUERY 0 2 2
UPDATE 3 0 3 688
QUERY 1 1 3
Sample Output 1
1588
2673
Sample Explanation 1
After the first UPDATE
, the values of the vertices are
After the second UPDATE
, the values of the vertices are
Sample Input 2
5 4
0 1 2 3
UPDATE 2 1 4 541
QUERY 0 1 4
UPDATE 0 1 3 134
QUERY 0 4 1
Sample Output 2
1623
0
Sample Explanation 2
After the first UPDATE
, the values of the vertices are
After the second UPDATE
, the values of the vertices are
Sample Input 3
5 4
0 1 1 3
UPDATE 3 0 4 544
QUERY 4 0 4
UPDATE 1 0 4 55
QUERY 0 0 4
Sample Output 3
544
764
Sample Explanation 3
After the first UPDATE
, the values of the vertices are
After the second UPDATE
, the values of the vertices are
Sample Input 4
5 4
0 1 1 3
UPDATE 0 1 2 667
QUERY 0 0 1
UPDATE 0 2 3 617
QUERY 0 2 3
Sample Output 4
667
6987
Sample Explanation 4
After the first UPDATE
, the values of the vertices are
After the second UPDATE
, the values of the vertices are
Comments