Problem · Array
Dynamic Pair Sum Queries
Learn this problemProblem statement
You are given two integer arrays a and b, and an array queries whose elements must be processed in order.
Each query has one of two forms:
[0, i, x]: assignxtoa[i].[1, x]: count the pairs of indices(i, j)such thata[i] + b[j] = x.
Return an array containing the counts produced by the type 1 queries, in query order.
Function
solution(a: int[], b: int[], queries: int[][]) → int[]Examples
Example 1
a = [3,4]b = [1,2,3]queries = [[1,5],[0,0,1],[1,5]]return = [2,1]Initially, two pairs sum to 5: a[0] + b[1] = 3 + 2 and a[1] + b[0] = 4 + 1.
The update [0, 0, 1] assigns 1 to a[0], so a becomes [1, 4].
For the final query, only a[1] + b[0] = 4 + 1 sums to 5.