Class Solution

  • All Implemented Interfaces:

    
    public final class Solution
    
                        

    3624 - Number of Integers With Popcount-Depth Equal to K II.

    Hard

    You are given an integer array nums.

    For any positive integer x, define the following sequence:

    • <code>p<sub>0</sub> = x</code>

    • <code>p<sub>i+1</sub> = popcount(p<sub>i</sub>)</code> for all i &gt;= 0, where popcount(y) is the number of set bits (1's) in the binary representation of y.

    This sequence will eventually reach the value 1.

    The popcount-depth of x is defined as the smallest integer d &gt;= 0 such that <code>p<sub>d</sub> = 1</code>.

    For example, if x = 7 (binary representation "111"). Then, the sequence is: 7 &rarr; 3 &rarr; 2 &rarr; 1, so the popcount-depth of 7 is 3.

    You are also given a 2D integer array queries, where each queries[i] is either:

    • [1, l, r, k] - Determine the number of indices j such that l &lt;= j &lt;= r and the popcount-depth of nums[j] is equal to k.

    • [2, idx, val] - Update nums[idx] to val.

    Return an integer array answer, where answer[i] is the number of indices for the <code>i<sup>th</sup></code> query of type [1, l, r, k].

    Example 1:

    Input: nums = 2,4, queries = [1,0,1,1,2,1,1,1,0,1,0]

    Output: 2,1

    Explanation:

    Thus, the final answer is [2, 1].

    Example 2:

    Input: nums = 3,5,6, queries = [1,0,2,2,2,1,4,1,1,2,1,1,0,1,0]

    Output: 3,1,0

    Explanation:

    Thus, the final answer is [3, 1, 0].

    Example 3:

    Input: nums = 1,2, queries = [1,0,1,1,2,0,3,1,0,0,1,1,0,0,2]

    Output: 1,0,1

    Explanation:

    Thus, the final answer is [1, 0, 1].

    Constraints:

    • <code>1 <= n == nums.length <= 10<sup>5</sup></code>

    • <code>1 <= numsi<= 10<sup>15</sup></code>

    • <code>1 <= queries.length <= 10<sup>5</sup></code>

    • queries[i].length == 3 or 4

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Constructor Summary

      Constructors 
      Constructor Description
      Solution()
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      final IntArray popcountDepth(LongArray nums, Array<LongArray> queries)
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait