Utkarsh and Party Row House
Practice
3.9 (54 votes)
Easy
Problem
52% Success 3285 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code

In the college where Utkarsh studies, all the students live in N Row Houses. The colony containing the Row Houses is a straight line = x axis. Ith Row House is located at x = i and Ai students live in it.

Every week the students of some Row House at x=K organize a party and invite all the students living in Row Houses from x=L to x=R.

Utkarsh wants you to handle Q events. An event can be one of the following 2 types.

  • 1 K L R: Row House at x=K organizes a party and invites all students living in Row House from x=L to x=R. Tell the sum of distance traveled by all the guests.
    If a guest is at x=i and party is at x=j then distance travelled by him alone is |i - j|.

  • 2 K S: S new students are admitted into the college and all of them start to live in Row House at x=K


Input format:
The first line contains 2 integers N and Q.
The second line contains N integers denoting entries of A.


Output format:
Print the result to all events of type 1.


Constraints:
1 ≤ N, Q ≤ 105
1 ≤ LRN
1 ≤ KN
1 ≤ Ai, S ≤ 105

NOTE: Row Houses are 1-indexed

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
4 votes
Tags:
Data StructuresEasyFenwick tree
Points:30
8 votes
Tags:
Data StructuresEasyFenwick TreeFenwick tree
Points:30
78 votes
Tags:
ApprovedEasyMathOpenReadySegment TreesTrees