#K88422. Sum of Squares in Range

    ID: 37305 Type: Default 1000ms 256MiB

Sum of Squares in Range

Sum of Squares in Range

You are given ( T ) test cases. For each test case, you are provided with two integers ( L ) and ( R ) which define an inclusive range, followed by a list of ( N ) integers. Your task is to compute the sum of squares of all those integers ( x ) from the list that satisfy ( L \le x \le R ), i.e. compute ( \sum_{x: L \le x \le R} x^2 ). This problem tests your ability to parse input, iterate through data, and apply conditional arithmetic operations. The input is read from standard input and the output should be directed to standard output.

inputFormat

The first line contains an integer ( T ) representing the number of test cases. Each test case consists of three parts:

  1. A line with two space-separated integers ( L ) and ( R ) (the inclusive range).
  2. A line with an integer ( N ) representing the number of elements.
  3. A line with ( N ) space-separated integers.

outputFormat

For each test case, output a single line containing the sum of the squares of all integers ( x ) such that ( L \le x \le R ).## sample

3
5 10
6
1 3 5 7 9 11
-10 -5
5
-1 -2 -3 -6 -10
0 10
4
0 1 10 100
155

136 101

</p>