HORRIBLE - 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 - output a line containing a single integer which is the sum of all the array elements between p and q (inclusive)

 

Input

In the first line you'll be given T, number of test cases.

Each test case will start with N (N <= 100 000) and C (C <= 100 000). After that you'll be given C commands in the format as mentioned above. 1 <= p, q <= N and 1 <= v <= 10^7.

Output

Print the answers of the queries.

Example

Input:
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:
80
508

hide comments
Hikari9: 2014-10-28 00:44:32

%llu is keyword for <unsigned long long int>

Numbers can be signed, so use %lld instead

Azure: 2014-10-27 00:45:55

Thanks! Umair Khan
I have no idea why - but your comment helped!

Umair Khan: 2014-10-19 11:48:45

Apparently, printf("%llu", <derp>) is giving WA and cout<<<derp> got AC.
Anyone willing to answer why ?

Agam Gupta: 2014-09-27 12:17:00

awesome problem..learned a lot...
though silly mistake caused me 4 WAs

Bala sai charan: 2014-07-23 18:52:52

segment tree got accpted with 2.63sec

Luqman Arifin: 2014-07-08 08:15:48

Such a beautiful problem to be solved by BIT :)

Afrizal: 2014-07-03 18:15:35

Expected solution : BIT, realization : segtree =))

sobriquet: 2014-07-03 09:36:01

Amazing problem if solved by BIT. Lazy update does the job for Segment Tree. And BIT is HORRIBLY faster than Segment Tree. :-)

Archit Jain: 2014-07-01 20:32:58

silly mistake caused tonnes of wa...
segment tree + lazy optimization AC in 2.62 sec

use long long int

Last edit: 2014-07-01 20:52:45
fanatique: 2014-06-15 09:10:58

bit-ac
segment trees-tle
@nitish25 thanks..
advice for segment trees required..

Last edit: 2014-06-15 09:11:46

Added by:Iqram Mahmud
Date:2010-12-04
Time limit:2.329s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64
Resource:Own. Thanks to Emir Habul.