Class Solution
-
- All Implemented Interfaces:
public final class Solution3624 - 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 >= 0, wherepopcount(y)is the number of set bits (1's) in the binary representation ofy.
This sequence will eventually reach the value 1.
The popcount-depth of
xis defined as the smallest integerd >= 0such that <code>p<sub>d</sub> = 1</code>.For example, if
x = 7(binary representation"111"). Then, the sequence is:7 → 3 → 2 → 1, so the popcount-depth of 7 is 3.You are also given a 2D integer array
queries, where eachqueries[i]is either:[1, l, r, k]- Determine the number of indicesjsuch thatl <= j <= rand the popcount-depth ofnums[j]is equal tok.[2, idx, val]- Updatenums[idx]toval.
Return an integer array
answer, whereanswer[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
answeris[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
answeris[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
answeris[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 == 3or4