Good Measures of Dispersion

A deadly war is going on between two neighboring states, A and B. The army of B established N bunkers in the frontline numbered by 1, 2, ..., N. The chief of the army of A knows very well about the new intake of soldiers of B in the bunkers. He wants to attack and destroy each bunker of B. He needs to know about the strength of the bunkers very frequently. He is more concerned about some very good measures of dispersion of a segment of bunkers because he needs to know how much the strength varies among them. Here, he mainly wants to know the Range and Variance of strengths of a segment. Range is the absolute difference between the minimum and maximum values of a segment. Variance of a set of numbers x1, x2, ..., xm is defined as follows ∑∑ Input There will be T (T ≤ 12) test cases in the input file. First line of the input contains two positive integers, N (N ≤ 100, 000) and Q (Q ≤ 100, 000). The next line contains N integers which indicate the initial strengths of the N bunkers. The absolute value of the initial strength of any bunker can be at most 1,000. Each of the next Q lines starts with a number (‘0’, ‘1’, or ‘2’), which indicates the type of operation. ‘2’ is followed by 2 integers, st and nd, which indicate that the chief wants to know the Variance and Range of current strengths between st and nd, inclusive. ‘0’ and ‘1’ are followed by 3 integers, st, nd andx(1≤st≤nd≤N and−1,000≤x≤1,000). Eachlinestartingwith‘0’meansxisthenew strength of each bunker between st and nd, inclusive. Each line starting with ‘1’ means x is added to the strength of each bunker between st and nd, inclusive. Output For each test case output the ‘Case < x >:’ in the first line (where x = case number) and from the second line output the Variance and Range for each type ‘2’ operations in a separate line as shown in the sample output. The Variance should be printed as a fraction, reduced to the lowest terms. The absolute value of numerator or denominator will never be greater than 263–1, even before the reduction of the fraction to the lowest terms. Intermediate overflow will not occur with proper use of 64-bit signed integer. Sample Input 1 96 -1 3 2 4 -2 8 0 5 -7 236 0552 236 1471 237 211 mi=1(xi − x)2 mi=1 xi V (x) = m , where x = m

2/2 Sample Output Case 1: 13/1 10 6/1 6 8/1 8 0/1 0