human
Write me a code to mO 's Algorithm (Query Square Root Decomposition) and the other steps required given the following:
MO 's Algorithm (Query Square Root Decomposition) | Set 1 (Introduction) | Function that accepts array and list of queries and print sum of each query.
Traverse through each query.
Extract left and right indices.
Compute sum of current query range.
Print sum of current query range.
Driver script"
Solution in Python:
assistant
#Here is code to mO 's Algorithm (Query Square Root Decomposition) and the other steps required.
 def printQuerySum ( arr , Q ) :
	for q in Q :
		L , R = q
		s = 0
		for i in range ( L , R + 1 ) :
			s += arr [ i ]
		print ( " Sum ▁ of " , q , " is " , s )
arr = [ 1 , 1 , 2 , 1 , 3 , 4 , 5 , 2 , 8 ]
Q = [ [ 0 , 4 ] , [ 1 , 3 ] , [ 2 , 4 ] ]
printQuerySum ( arr , Q )