#C11732. Weighted Sum Queries

    ID: 41081 Type: Default 1000ms 256MiB

Weighted Sum Queries

Weighted Sum Queries

You are given an array \(A\) of \(N\) integers and \(Q\) queries. For each query, you are given two indices \(L\) and \(R\) (1-indexed). Your task is to compute the weighted sum for the subarray \(A[L..R]\) according to the formula:

\(S = \sum_{i=L}^{R} i \times A_{i}\)

For each query, output a single line containing the corresponding weighted sum.

Note: The index used in the weighted sum calculation is based on 1-indexing.

inputFormat

The input is given in the following format:

  1. The first line contains two integers \(N\) and \(Q\), representing the number of elements in the array and the number of queries.
  2. The second line contains \(N\) space-separated integers, representing the elements of the array \(A\).
  3. The next \(Q\) lines each contain two integers \(L\) and \(R\) representing a query.

The weighted sum for a query is computed as \(S = \sum_{i=L}^{R} i \times A_{i}\), where \(i\) is the 1-indexed position of the element.

outputFormat

For each query output the computed weighted sum on a new line.

## sample
6 1
1 2 3 4 5 6
1 6
91