Tap here to switch tabs
Problem
Submissions

Problem: Apply Operations on Array to Maximize Sum of Squares

Apply Operations on Array to Maximize Sum of Squares lets you repeatedly replace a pair with their bitwise AND and OR, then return the maximum sum of squares from k final values, modulo a prime.

Statement

You are given a 00 indexed integer array nums and a positive integer k.

In one operation, you can choose two distinct indices i and j such that 0≤0 \leq i, j << nums.length, and simultaneously replace nums[i] with (nums[i] AND nums[j]) and nums[j] with (nums[i] OR nums[j]), where AND denotes the bitwise AND operation and OR denotes the bitwise OR operation.

You may apply this operation any number of times.

Return the maximum possible sum of squares of any k elements chosen from the final array. Since the result can be very large, return it modulo 109+710^9 + 7.

Constraints:

  • 1≤1 \leq k ≤\leq nums.length ≤105\leq 10^5

  • 1≤1 \leq nums[i] ≤109\leq 10^9

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Apply Operations on Array to Maximize Sum of Squares

Apply Operations on Array to Maximize Sum of Squares lets you repeatedly replace a pair with their bitwise AND and OR, then return the maximum sum of squares from k final values, modulo a prime.

Statement

You are given a 00 indexed integer array nums and a positive integer k.

In one operation, you can choose two distinct indices i and j such that 0≤0 \leq i, j << nums.length, and simultaneously replace nums[i] with (nums[i] AND nums[j]) and nums[j] with (nums[i] OR nums[j]), where AND denotes the bitwise AND operation and OR denotes the bitwise OR operation.

You may apply this operation any number of times.

Return the maximum possible sum of squares of any k elements chosen from the final array. Since the result can be very large, return it modulo 109+710^9 + 7.

Constraints:

  • 1≤1 \leq k ≤\leq nums.length ≤105\leq 10^5

  • 1≤1 \leq nums[i] ≤109\leq 10^9