Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class FindSumPairs {
- public:
- unordered_map<long long, long long> count2;
- unordered_map<long long, long long> count1;
- vector<int> n2, n1;
- FindSumPairs(vector<int>& nums1, vector<int>& nums2) {
- n2 = nums2; n1 = nums1;
- for(auto num: nums2)
- count2[num]++;
- for(auto num: nums1)
- count1[num]++;
- }
- void add(int index, int val) {
- long long tmp = n2[index];
- n2[index] += val;
- count2[tmp]--;
- count2[n2[index]]++;
- }
- int count(int tot) {
- long long ans=0;
- for(auto p: count1){
- long long num = p.first;
- if(tot < num)continue;
- int rem = tot - num;
- if(count2.count(rem))
- ans += (count1[num]*count2[rem]);
- }
- return ans;
- }
- };
- /**
- * Your FindSumPairs object will be instantiated and called as such:
- * FindSumPairs* obj = new FindSumPairs(nums1, nums2);
- * obj->add(index,val);
- * int param_2 = obj->count(tot);
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement