#K72937. Sequence Modification and Cumulative Sum

    ID: 33864 Type: Default 1000ms 256MiB

Sequence Modification and Cumulative Sum

Sequence Modification and Cumulative Sum

You are given an integer \(n\) representing the number of elements in an initial sequence \(A = [A_1, A_2, \dots, A_n]\) and an integer \(m\) which is the number of queries. You will be provided with \(m\) queries where each query is represented as three integers \((op, x, y)\).

For each query:

  • If \(op = 1\): Add \(y\) to each element in the sequence from index \(x\) to \(n\) (indices are 1-indexed). In other words, for every index \(i\) such that \(i \ge x\), perform \(A_i = A_i + y\).
  • If \(op = 2\): Set the element at index \(x\) to \(y\), i.e. \(A_x = y\).

After processing all queries, print the cumulative sum of the modified sequence, i.e. \(\sum_{i=1}^{n} A_i\).

Example:

Input:
5 3
1 2 3 4 5
1 3 2
2 1 10
1 4 1

Output: 32

</p>

inputFormat

The first line of input contains two integers \(n\) and \(m\), where \(n\) is the length of the sequence and \(m\) is the number of queries.

The second line contains \(n\) integers representing the initial sequence \(A_1, A_2, \dots, A_n\).

Each of the following \(m\) lines contains three integers \(op\), \(x\), and \(y\) representing a query.

outputFormat

Output a single integer representing the cumulative sum of the sequence after all queries have been processed.

## sample
5 3
1 2 3 4 5
1 3 2
2 1 10
1 4 1
32