Task:

Implement a C function that performs a series of operations on an integer array nums according to the following rules:

Input:
nums: An array of positive integers.
numsSize: The size of the nums array.
k: The number of operations to perform.
multiplier: A positive integer multiplier.
Operations:
Perform the following for k iterations:
Find the Minimum:
Identify the minimum value x in nums.
If there are multiple occurrences of x, select the one with the smallest index (i.e., the first occurrence).
Update the Value:
Replace the selected minimum value x with x * multiplier.
Post-Processing:
After completing all k operations, apply the modulo 10^9 + 7 to each element in nums.
Output:
Return an array representing the final state of nums after all operations and modulo application.
Constraints:

1 <= nums.length <= 10^4
1 <= nums[i] <= 10^9
1 <= k <= 10^9
1 <= multiplier <= 10^6
Examples:

Example 1:


Input: nums = [2, 1, 3, 5, 6], k = 5, multiplier = 2

Operations:

1) Find min(1) at index 1
   nums[1] = 1 * 2 = 2
   nums = [2, 2, 3, 5, 6]

2) Find min(2) at index 0
   nums[0] = 2 * 2 = 4
   nums = [4, 2, 3, 5, 6]

3) Find min(2) at index 1
   nums[1] = 2 * 2 = 4
   nums = [4, 4, 3, 5, 6]

4) Find min(3) at index 2
   nums[2] = 3 * 2 = 6
   nums = [4, 4, 6, 5, 6]

5) Find min(4) at index 0
   nums[0] = 4 * 2 = 8
   nums = [8, 4, 6, 5, 6]

After modulo operation:
nums = [8, 4, 6, 5, 6]

Output: [8, 4, 6, 5, 6]
Example 2:


Input: nums = [100000, 2000], k = 2, multiplier = 1000000

Operations:

1) Find min(2000) at index 1
   nums[1] = 2000 * 1,000,000 = 2,000,000,000
   nums = [100,000, 2,000,000,000]

2) Find min(100,000) at index 0
   nums[0] = 100,000 * 1,000,000 = 100,000,000,000
   nums = [100,000,000,000, 2,000,000,000]

After modulo operation:
nums[0] = 100,000,000,000 % 1,000,000,007 = 999,999,307
nums[1] = 2,000,000,000 % 1,000,000,007 = 999,999,993

Output: [999,999,307, 999,999,993]
Function Signature:


/**
 * Note: The returned array must be malloced, assume caller calls free().
 */
int* getFinalState(int* nums, int numsSize, int k, int multiplier, int* returnSize) {

}
Requirements:

Implement the getFinalState function in C.
The function should return a newly allocated array containing the final state of nums.
Set *returnSize to numsSize.
Considerations for Large Inputs:

Since k can be up to 10^9, it's important to optimize the solution to handle large values efficiently.
Avoid timeouts by not performing operations iteratively when unnecessary.
Think about patterns or mathematical strategies to simulate the effect of multiple operations without iterating through each one.
Instructions:

Understand the Problem:
You need to perform k operations where each operation updates the minimum element.
For large k, iterating k times is not feasible due to time constraints.
Optimize for Large k:
Since you always update the minimum element, consider how many times each unique value will be updated.
Use data structures like priority queues (min-heaps) to efficiently find and update the minimum element.
For values that become the new minimum after updates, keep track accordingly.
Handle Large Numbers:
Use 64-bit integers (int64_t or long long) to prevent integer overflow.
Apply modulo operation as needed.
Test Your Code:
Use the provided examples and create additional test cases.
Ensure your code handles edge cases, such as when all elements are the same.
Memory Management:
Allocate memory for the return array using malloc.
Ensure no memory leaks by freeing any allocated memory that is no longer needed.
Set returnSize:
Before returning, set *returnSize = numsSize.
Goal:

Write efficient and robust code that can handle large inputs within the specified constraints.
Ensure that the function returns the correct final state of the array after all operations.