Help

All submissions for this problem are available.
Gagan was given a one dimensional integer array A of length N. Mayank challange him to maintain the array under Q queries of the following four types.
Assume 1based indexing and where M = 1000000000 + 7.
Query 1 : 1 x y
This is a report query which needs to find the sum of the values in A from x to y,(inclusive A[x] and A[y]).
Query 2 : 2 v x y
This implies adding v to array A to all the indices from x to y,(inclusive A[x] and A[y]).
Query 3 : 3 v x y
This implies initializing the array A at all the indices from x to y with the value v,(inclusive A[x] and A[y]).
Query 4 : 4 v x y
This implies multiplying the scalar v with the array A for all the indices from x to y,(inclusive A[x] and A[y]).
Note: a%b represents the remainder of a when divided by b.
Input
 First line contains two space separated integers N, Q.
 Next line contains N space separated integers denoting the array A.
 Next Q lines contain queries which can be of any of the above four types.
Output
For each query of type 1, output a single integer corresponding to the answer in a newline. Gagan ask you for help. Help him! .
Constraints
 1 ≤ N ≤ 100000
 1 ≤ Q ≤ 100000
 1 ≤ Initial value of Ai ≤ 1000000000
 1 ≤ v ≤ 1000000000
Subtasks :
Example
Input: 4 4 1 2 3 4 1 1 4 2 10 1 3 4 2 2 4 1 1 4 Output: 10 69
Explanation
Initial State of array is [1 2 3 4]
Query1: 1 1 4 Add all numbers from index 1 to 4 i.e. 1+2+3+4=10, hence printing 10
Query 2: 2 10 1 3 Add 10 to numbers from index 1 to 3 i.e. Array becomes [11 12 13 4]
Query 3: 4 2 2 4 Multiply 2 to numbers from index 2 to 4 i.e. Array becomes [11 24 26 8]
Query 4: 1 1 4 Add all numbers from index 1 to 4 i.e. 11 + 24 + 26+ 8=69 , hence printing 69
Author:  gagan86nagpal 
Tags  gagan86nagpal 
Date Added:  19102016 
Time Limit:  1 sec 
Source Limit:  50000 Bytes 
Languages:  C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, SCALA, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, PERL6, TEXT, SCM chicken, CLOJ, FS 
Comments
 Please login at the top to post a comment.
SUCCESSFUL SUBMISSIONS
Fetching successful submissions