1679B.md (2539B)
1 Source: https://codeforces.com/problemset/problem/1679/B 2 3 B. Stone Age Problem 4 5 time limit per test 6 7 2 seconds 8 9 memory limit per test 10 11 256 megabytes 12 13 input 14 15 standard input 16 17 output 18 19 standard output 20 21 Once upon a time Mike and Mike decided to come up with an outstanding problem for some stage of ROI (rare olympiad in informatics). One of them came up with a problem prototype but another stole the idea and proposed that problem for another stage of the same olympiad. Since then the first Mike has been waiting for an opportunity to propose the original idea for some other contest... Mike waited until this moment! 22 23 You are given an array $a$ of $n$ integers. You are also given $q$ queries of two types: 24 25 * Replace $i$-th element in the array with integer $x$. 26 * Replace each element in the array with integer $x$. 27 28 After performing each query you have to calculate the sum of all elements in the array. 29 30 Input 31 32 The first line contains two integers $n$ and $q$ ($1 \le n, q \le 2 \cdot 10^5$) — the number of elements in the array and the number of queries, respectively. 33 34 The second line contains $n$ integers $a_1, \ldots, a_n$ ($1 \le a_i \le 10^9$) — elements of the array $a$. 35 36 Each of the following $q$ lines contains a description of the corresponding query. Description begins with integer $t$ ($t \in \{1, 2\}$) which denotes a type of the query: 37 38 * If $t = 1$, then two integers $i$ and $x$ are following ($1 \le i \le n$, $1 \le x \le 10^9$) — position of replaced element and it's new value. 39 * If $t = 2$, then integer $x$ is following ($1 \le x \le 10^9$) — new value of each element in the array. 40 41 Output 42 43 Print $q$ integers, each on a separate line. In the $i$-th line print the sum of all elements in the array after performing the first $i$ queries. 44 45 Example 46 47 Input 48 49 ``` 50 5 5 51 1 2 3 4 5 52 1 1 5 53 2 10 54 1 5 11 55 1 4 1 56 2 1 57 ``` 58 59 Output 60 61 ``` 62 19 63 50 64 51 65 42 66 5 67 ``` 68 69 Note 70 71 Consider array from the example and the result of performing each query: 72 73 1. Initial array is $[1, 2, 3, 4, 5]$. 74 2. After performing the first query, array equals to $[5, 2, 3, 4, 5]$. The sum of all elements is $19$. 75 3. After performing the second query, array equals to $[10, 10, 10, 10, 10]$. The sum of all elements is $50$. 76 4. After performing the third query, array equals to $[10, 10, 10, 10, 11$]. The sum of all elements is $51$. 77 5. After performing the fourth query, array equals to $[10, 10, 10, 1, 11]$. The sum of all elements is $42$. 78 6. After performing the fifth query, array equals to $[1, 1, 1, 1, 1]$. The sum of all elements is $5$.