Sum Of Squares

Try First, Check Solution later

1. You should first read the question and watch the question video.
2. Think of a solution approach, then try and submit the question on editor tab.
3. We strongly advise you to watch the solution video for prescribed approach.

`You are given an array(of integers) of length n.You are required to answer q queries.Queries can be of two types0. 0 l r : In this you have to return sum of squares of all elements int range [l, r].1. 1 l r val: In this query u have to increase all elements in this interval [l, r] by val.To do the above task u have to create a datastructure as follows :-Implement the SegmentTree class:1. SegmentTree(int arr[]): Initializes the SegmentTree object with an array,2. void update(int l, int r, int val): increase all elements in this interval [l, r] by val,3. long query(int l, int r): return sum of squares of all elements arr[i] for which i is in range [l, r].`
Input Format
`A number nn1n2.. n number of elementsA number qfollowing q lines contains queries of format0 l r1 l r val`
Output Format
`for each query of type 0 print a single integer in seperate line`
Question Video
Constraints
`1. 1 <= n, q <= 10^52. 0 <= l <= r < n3. -10^4 <= arr[i], val <= 10^4.`
Sample Input
`801010-15810250 7 71 4 6 10 2 41 5 5 70 3 7`
Sample Output
`4137418`

• Related Topics

Run

Run
Id Name