-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path1865.cpp
More file actions
30 lines (25 loc) · 708 Bytes
/
Copy path1865.cpp
File metadata and controls
30 lines (25 loc) · 708 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
class FindSumPairs {
unordered_map<int, int> count1, count2;
vector<int> arr;
public:
FindSumPairs(const vector<int> &nums1, const vector<int> &nums2) : arr(nums2) {
for (const int n : nums1)
count1[n]++;
for (const int n : nums2)
count2[n]++;
}
void add(int index, int val) {
count2[arr[index]]--;
arr[index] += val;
count2[arr[index]]++;
}
int count(int tot) const {
int res = 0;
for (const auto [k, v] : count1) {
const auto it = count2.find(tot - k);
if (!v || it == count2.end()) continue;
res += v * it->second;
}
return res;
}
};