Tap here to switch tabs
Problem
Submissions

Problem: Minimum Operations to Make Array Elements Zero

Try to solve the Minimum Operations to Make Array Elements Zero problem.

Statement

You are given a 22D integer array queries, where queries[i] = [l, r].

For each query, an array nums is formed containing consecutive integers from l to r inclusive, such that nums =[l,l+1,…,r]= [l, l + 1, \dots, r].

In a single operation, you can select two distinct indices i and j where nums[i] > 0 and nums[j] > 0, and simultaneously replace nums[i] with ⌊extnums[i]/4⌋\lfloor ext{nums}[i] / 4 \rfloor and nums[j] with ⌊extnums[j]/4⌋\lfloor ext{nums}[j] / 4 \rfloor.

Return the sum of the minimum number of operations required to reduce all elements of nums to 00 for all queries.

Constraints:

  • 1≤1 \leq queries.length ≤105\leq 10^5

  • queries[i].length =2= 2

  • queries[i] =[l,r]= [l, r]

  • 1≤l<r≤1091 \leq l < r \leq 10^9

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Minimum Operations to Make Array Elements Zero

Try to solve the Minimum Operations to Make Array Elements Zero problem.

Statement

You are given a 22D integer array queries, where queries[i] = [l, r].

For each query, an array nums is formed containing consecutive integers from l to r inclusive, such that nums =[l,l+1,…,r]= [l, l + 1, \dots, r].

In a single operation, you can select two distinct indices i and j where nums[i] > 0 and nums[j] > 0, and simultaneously replace nums[i] with ⌊extnums[i]/4⌋\lfloor ext{nums}[i] / 4 \rfloor and nums[j] with ⌊extnums[j]/4⌋\lfloor ext{nums}[j] / 4 \rfloor.

Return the sum of the minimum number of operations required to reduce all elements of nums to 00 for all queries.

Constraints:

  • 1≤1 \leq queries.length ≤105\leq 10^5

  • queries[i].length =2= 2

  • queries[i] =[l,r]= [l, r]

  • 1≤l<r≤1091 \leq l < r \leq 10^9