Gary and Queries

3.9

10 votes
Algorithms, Data Structures, Medium, Sqrt-Decomposition
Problem

Gary likes to solve algorithmic problems but he doesn't like problems that involve queries. His school teacher gave him an assignment full of problems but one of them involve queries. Can you help Gary in solving that problem so that he can go and play with his friends? The problem is :

Given an Array A consisting of N positive integers, you have to answer Q queries on it. Queries can be of the two types:

  • 1XY - Update the value of the Xth element in the array to Y.
  • 2X - Print the value of ni=1AiX where denotes Greatest Integer Function.

Input:
The first line contains two space separated integers N and Q.
Next line contains N space separated integers denoting array A.
Next Q lines contain queries of one of the above mentioned type format.

Output:
Answer to the each query of type 2 in a new line .

Constraints:
1N5105
1Q5105
1Ai,X,Y5105

Time Limit: 5
Memory Limit: 256
Source Limit:
Explanation

After query 1 the array becomes : 3 3 2 1 2
Answer for query 2 is : 35+35+25+15+25=0
After query 3 the array becomes : 3 3 2 4 2
Answer for query 4 is : 31+31+21+41+21=14

Editor Image

?