Sum Of Squares
You are given an array(of integers) of length n.Input Format
You are required to answer q queries.
Queries can be of two types
0. 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].
A number nOutput Format
n1
n2
.. n number of elements
A number q
following q lines contains queries of format
0 l r
1 l r val
for each query of type 0 print a single integer in seperate lineQuestion Video
1. 1 <= n, q <= 10^5Sample Input
2. 0 <= l <= r < n
3. -10^4 <= arr[i], val <= 10^4.
8Sample Output
0
10
10
-1
5
8
10
2
5
0 7 7
1 4 6 1
0 2 4
1 5 5 7
0 3 7
4
137
418
-
Asked in Companies
-
Related Topics
Video Solution
Code Solution
{ }
{ }
Run