#K73797. Sum of Even Numbers After Array Queries

    ID: 34055 Type: Default 1000ms 256MiB

Sum of Even Numbers After Array Queries

Sum of Even Numbers After Array Queries

You are given an array of n integers and q update queries. Each query provides an index and a new value, and you are required to update the array at the given index. After processing all the queries, compute and output the sum of all even numbers in the final array.

More formally, you are given two integers \(N\) and \(Q\), an array \(A=[a_0,a_1,\dots,a_{N-1}]\), and \(Q\) queries. Each query is represented by a pair of integers \((i, v)\) which means that \(a_i\) should be updated to \(v\). After all queries have been executed, output the value of \[ \text{even_sum} = \sum_{j=0}^{N-1} \mathbf{1}_{\{a_j \text{ is even}\}}\cdot a_j \] where \(\mathbf{1}_{\{condition\}}\) is an indicator function that is 1 if the condition is true, and 0 otherwise.

Note: The queries are processed sequentially and each update affects subsequent queries.

inputFormat

The input is read from stdin and is structured as follows:

  • The first line contains two space-separated integers \(N\) and \(Q\), where \(N\) is the size of the array and \(Q\) is the number of queries.
  • The second line contains \(N\) space-separated integers representing the array \(A\).
  • The next \(Q\) lines each contain two space-separated integers \(i\) and \(v\), representing a query that updates the element at index \(i\) to the value \(v\).

outputFormat

Print a single integer representing the sum of all even numbers in the array after processing all queries. The output should be written to stdout.

## sample
5 3
1 2 3 4 5
1 10
2 6
4 8
28