Urbancompany OA IIT|| BIT || FTE
Anonymous User
612

Strange sum
Given an array "a" of size n having elements a1,a2,a3......an, strange sum is defined as
S_n = 1*a1 + 2*a2 + 3*a3 + 4*a4 ......... n*an

There will be Q queries of 2 different types:
1 l r : return strange sum in range l to r
2 i k : update i th element of array to k

eg. a = [2,3,4,5,6]  // array is 1 indexed 
Queries
1 3 5
2 4 10
1 2 4
Ans: 
From query 1: 1*4+2*5+3*6
From query 2: a = [2,3,4,10,6]
From query 3: 1*3+2*4+3*10

Constraints: 1<Q<N<2e5
Dont worry about overflow... It can be taken care of by mod.
I thought of using BIT but was not able to move forward with it. Any help would be appreciated.

Comments (1)