Bob And Array Queries
Practice
4.2 (29 votes)
Advanced data structures
Data structures
Easy
Segment trees
Problem
91% Success 16565 Attempts 20 Points 1s Time Limit 256MB Memory 1024 KB Max Code

Bob has an array A[] of N integers. Initially, all the elements of the array are zero. Bob asks you to perform Q operations on this array.

There are three types of operations that can be performed:

  1.  1 X: Update the value of A[X] to  2 * A[X] + 1.
  2.  2 X: Update the value A[X] to \(\lfloor\) A[x]/2 \(\rfloor\), where \(\lfloor\)\(\rfloor\) is Greatest Integer Function.
  3.  3 X Y: Take all the A[i] such that  X <= i <= Y and convert them into their corresponding binary strings. Now concatenate all the binary strings and find the total no. of '1' in the resulting string.

Note: It is guaranteed that there is at least 1 type-3 query in the every test case. All the array elements will fit into 64 bit integers.

Input Format:
First line consists of two space-separated integers N and Q.
Next, Q lines consist of Q operations of either of the 3 types as described above.

Output Format:
For each type-3 query print the answer that is the no. of '1' in the resulting string.

Constraints:
\(1 \le N,Q \le 500000\)
\(1 \le X \le Y \le N\)

 

 

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:20
65 votes
Tags:
AlgorithmsApprovedEasyOpenTrees
Points:20
19 votes
Tags:
Advanced Data StructuresBit ManipulationData StructuresEasySegment Trees
Points:20
42 votes
Tags:
Bit ManipulationData StructuresEasySegment Trees