GUPTA MECHANICAL

IN THIS WEBSITE I CAN TELL ALL ABOUT TECH. TIPS AND TRICKS APP REVIEWS AND UNBOXINGS ALSO TECH. NEWS .............

Saturday 14 May 2022

[Solution] Stone Age Problem Codeforces Solution | Codeforces Problem Solution 2022

B. Stone Age Problem
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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 a of n integers. You are also given q queries of two types:

  • Replace i-th element in the array with integer x.
  • Replace each element in the array with integer x.

Solution Click Below:-  CLICK HERE

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

Input

The first line contains two integers n and q (1n,q2105) — the number of elements in the array and the number of queries, respectively.


The second line contains n integers a1,,an (1ai109) — elements of the array a.

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

  • If t=1, then two integers i and x are following (1in1x109) — position of replaced element and it's new value.
  • If t=2, then integer x is following (1x109) — new value of each element in the array.
Output

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.

Join Now for Solution:- 

No comments:

Post a Comment