Problem Brief
Number of Unique Elements After Modifications π
OA
You are given an array of nums of size n and queries of size m.
For each queries you need to perform the following operation:
- Update
A[L-1] = A[L-1] - xwhereLisqueries[i][0]value of query andxisqueries[i][1]value of each indexi. - Copy the modified array in
Bsuch thatA[0] = B[0]andB[i] = min(B[i-1], A[i])for1 <= i < n.
Your result should be the unique number of elements in B after every operation.
res[i] denotes the result after ith operation.
Return the result array after performing all the operations.
1Example 1
Input
nums = [5, 7, 2, 2, 4], queries = [[3, 5], [5, 4]]
Output
[2, 3]
Explanation
After the first operation,
A is 5 5 2 2 4 then copy it to B as per the rule then we get B as 5 5 2 2 2 so the result after the 1st operation is 2. After the 2nd operation, A becomes 5 5 2 2 0 then we get B as 5 5 2 2 0 so the result after the 2nd operation is 3. Then the final result is {2,3}.Constraints
Limits and guarantees your solution can rely on.
1 <= n <= 1e51 <= m <= 1e51 <= A[i] <= 1e91 <= Q[i][j] <= 1e5