#C6182. Array Query Processing

    ID: 49914 Type: Default 1000ms 256MiB

Array Query Processing

Array Query Processing

You are given an array of \( n \) integers and \( q \) queries. The queries have two types:

  • Type 1: 1 L R X
    • Add the integer \( X \) to each element in the subarray from index \( L \) to \( R \) (1-indexed).
  • Type 2: 2 L R
    • Output the sum of the subarray from index \( L \) to \( R \) (1-indexed).

Process the queries sequentially and for every query of type 2, print the result on a new line.

inputFormat

The input is read from standard input and has 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, respectively.
  2. The second line contains \( n \) space-separated integers, the elements of the array.
  3. The next \( q \) lines each represent a query in one of the following formats:
    • For a type 1 query: 1 L R X
    • For a type 2 query: 2 L R

outputFormat

For each type 2 query, output the sum of the specified subarray on a new line.

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

24

</p>