#SGM0000038. Tổng bình phương với cây đoạn (Sum of Squares with Segment Tree)
Tổng bình phương với cây đoạn (Sum of Squares with Segment Tree)
Sum of Squares with Segment Tree
Source: SPOJ
Version: Phuoc Hung OJ Extended
Problem Statement
Maintain an array with range assignment and range addition; queries return the sum of squares on a range.
Input
The first line contains and the next line the array. Operations are:
0 l r x: assign every value in to .1 l r x: add to every value in .2 l r: print .
Output
Print one line for each type 2 query. The PHOJ version omits the original multi-case Case k: line.
Subtasks
- 20 points: .
- 30 points: .
- 50 points: , ; use 64-bit signed integers for intermediate values.
Examples
Input
4 5
1 2 3 4
2 1 4
0 3 4 1
2 1 4
1 3 4 1
2 1 4
Output
30
7
13
Explanation
The initial square sum is . Assigning the last two values to 1 gives . Adding 1 to those two positions produces 1 2 2 2, whose square sum is 13.