CF1679B.Stone Age Problem

普及-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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!

You are given an array aa of nn integers. You are also given qq queries of two types:

  • Replace ii-th element in the array with integer xx.
  • Replace each element in the array with integer xx.

After performing each query you have to calculate the sum of all elements in the array.

从前,两位 Mike 决定为某届 ROI(罕见信息学奥林匹克竞赛)设计一道出色的题目。其中一位提出了一个题目的雏形,但另一位却窃取了这个创意,并将该题目提交给了同一届奥林匹克竞赛的另一场赛事。自那以后,第一位 Mike 便一直在等待机会,将原始创意提交给其他比赛……Mike 一直等到了此刻!

给你一个包含 nn 个整数的数组 aa,以及 qq 个查询,查询分为两种类型:

  • 将数组中第 ii 个元素替换为整数 xx;
  • 将数组中所有元素均替换为整数 xx。

在每次执行查询后,你都需要计算并输出数组中所有元素的和。

输入格式

The first line contains two integers nn and qq (1≤n,q≤2⋅1051 \le n, q \le 2 \cdot 10^5) — the number of elements in the array and the number of queries, respectively.

The second line contains nn integers a1,…,ana_1, \ldots, a_n (1≤ai≤1091 \le a_i \le 10^9) — elements of the array aa.

Each of the following qq lines contains a description of the corresponding query. Description begins with integer tt (t∈1,2t \in {1, 2}) which denotes a type of the query:

  • If t=1t = 1, then two integers ii and xx are following (1≤i≤n1 \le i \le n, 1≤x≤1091 \le x \le 10^9) — position of replaced element and it's new value.
  • If t=2t = 2, then integer xx is following (1≤x≤1091 \le x \le 10^9) — new value of each element in the array.

第一行包含两个整数 nn 和 qq(1≤n,q≤2⋅1051 \le n, q \le 2 \cdot 10^5)—— 分别表示数组中元素的个数和查询的个数。

第二行包含 nn 个整数 a1,…,ana_1, \ldots, a_n(1≤ai≤1091 \le a_i \le 10^9)—— 数组 aa 的元素。

接下来的 qq 行,每行描述一个对应的查询。每行以一个整数 tt(t∈{1,2}t \in \{1, 2\})开头,表示该查询的类型:

  • 若 t=1t = 1,则随后是两个整数 ii 和 xx(1≤i≤n1 \le i \le n, 1≤x≤1091 \le x \le 10^9)—— 表示被替换元素的位置及其新值;
  • 若 t=2t = 2,则随后是一个整数 xx(1≤x≤1091 \le x \le 10^9)—— 表示数组中每个元素的新值。

输出格式

Print qq integers, each on a separate line. In the ii-th line print the sum of all elements in the array after performing the first ii queries.

输出 qq 个整数,每个整数占一行。在第 ii 行中,输出执行前 ii 个查询后数组中所有元素的和。

输入输出样例

  • 输入#1

    5 5
    1 2 3 4 5
    1 1 5
    2 10
    1 5 11
    1 4 1
    2 1

    输出#1

    19
    50
    51
    42
    5

说明/提示

Consider array from the example and the result of performing each query:

  1. Initial array is [1,2,3,4,5][1, 2, 3, 4, 5].
  2. After performing the first query, array equals to [5,2,3,4,5][5, 2, 3, 4, 5]. The sum of all elements is 1919.
  3. After performing the second query, array equals to [10,10,10,10,10][10, 10, 10, 10, 10]. The sum of all elements is 5050.
  4. After performing the third query, array equals to [10,10,10,10,11[10, 10, 10, 10, 11]. The sum of all elements is 5151.
  5. After performing the fourth query, array equals to [10,10,10,1,11][10, 10, 10, 1, 11]. The sum of all elements is 4242.
  6. After performing the fifth query, array equals to [1,1,1,1,1][1, 1, 1, 1, 1]. The sum of all elements is 55.

考虑示例中的数组以及执行每个查询后的结果:

  1. 初始数组为 [1,2,3,4,5][1, 2, 3, 4, 5]。
  2. 执行第一个查询后,数组变为 [5,2,3,4,5][5, 2, 3, 4, 5]。所有元素之和为 1919。
  3. 执行第二个查询后,数组变为 [10,10,10,10,10][10, 10, 10, 10, 10]。所有元素之和为 5050。
  4. 执行第三个查询后,数组变为 [10,10,10,10,11][10, 10, 10, 10, 11]。所有元素之和为 5151。
  5. 执行第四个查询后,数组变为 [10,10,10,1,11][10, 10, 10, 1, 11]。所有元素之和为 4242。
  6. 执行第五个查询后,数组变为 [1,1,1,1,1][1, 1, 1, 1, 1]。所有元素之和为 55。

输入解题思路,AI测评打分。不知道怎么写?

首页