Dynamic Pair Sum Queries
Problem statement
You are given two integer arrays a and b and a sequence of queries. Process the queries in order.
- A query
[0, i, x]addsxtoa[i]. - A query
[1, x]asks for the number of index pairs(i, j)such that the current values satisfya[i] + b[j] = x.
Return the answers to all type-1 queries in their original order.
Function
processPairSumQueries(a: int[], b: int[], queries: int[][]) → long[]Examples
Example 1
a = [1,4]b = [1,2,3]queries = [[1,5],[0,0,2],[1,5]]return = [1,2]Before the update, only a[1] + b[0] = 4 + 1 = 5, so the first answer is 1. The update changes a[0] from 1 to 3. Then both 3 + 2 and 4 + 1 equal 5, so the second answer is 2.
Constraints
a,b, andqueriesare non-empty.- Every type-
0query has the form[0, i, x]with0 <= i < a.length. - Every type-
1query has the form[1, x]. - Array
bis never modified.