#K65412. Sum of Squares Query
Sum of Squares Query
Sum of Squares Query
You are given an array of n integers and Q queries. Each query provides two indices l and r. For each query, you are required to compute the sum of squares of the elements from index l to r (inclusive).
The mathematical formula for a single query is given by:
\( S = \sum_{i = l}^{r} a_i^2 \)
All indices are 0-indexed. Your task is to process all queries and output the result for each query on a new line.
inputFormat
The first line of input contains two integers n and Q, where n is the number of elements in the array and Q is the number of queries.
The second line contains n space-separated integers representing the array.
The next Q lines each contain two space-separated integers l and r, representing the starting and ending indices of the query, respectively.
outputFormat
For each query, output a single line containing the sum of squares of the elements in the array from index l to r (inclusive).
## sample5 2
1 2 3 4 5
1 3
0 4
29
55
</p>