Segment Tree - Multiple Update

Horrible Queries

World is getting more evil and it's getting tougher to get into the Evil League of Evil. Since the legendary Bad Horse has retired, now you have to correctly answer the evil questions of Dr. Horrible, who has a PhD in horribleness (but not in Computer Science). You are given an array of n elements, which are initially all 0. After that you will be given c commands. They are:

  • 0 p q v - you have to add v to all numbers in the range of p to q inclusive, where p and q are two indexes of the array.
  • 1 p q - print a line containing a single integer which is the sum of all the array elements between p and q inclusive.


The first line contains the number of test cases. Each test case starts with n (n100 000) and c (c100 000). After that you'll be given c commands in the format as mentioned above. It is known that 1p, qn and 1v107.


Print the answers to the queries.

Time limit 1 second
Memory limit 128 MiB
Input example #1
8 6
0 2 4 26
0 4 8 80
0 4 5 20
1 8 8 
0 5 7 14
1 4 8
Output example #1