Gary and Queries
Practice
3.9 (10 votes)
Algorithms
Data structures
Medium
Sqrt Decomposition
Problem
62% Success 5356 Attempts 50 Points 5s Time Limit 256MB Memory 1024 KB Max Code

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:

  • \(1\; X\; Y\) - Update the value of the Xth element in the array to Y.
  • \(2\; X\) - Print the value of \(\sum_{i=1}^{n} \left \lfloor{\frac{A_i}{X}}\right \rfloor\) where \(\left \lfloor{}\right \rfloor\) 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:
\(1 \le N \le 5 * 10^5\)
\(1 \le Q \le 5 * 10^5\)
\(1 \le A_i, X, Y \le 5 * 10^5\)

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:50
7 votes
Tags:
AlgorithmsMediumSquare Root DecompositionTrees
Points:50
2 votes
Tags:
AlgorithmsMediumSquare Root Decomposition
Points:50
1 votes
Tags:
AlgorithmsMediumSqrt-DecompositionSquare Root DecompositionString Manipulation