classFindSumPairs:def__init__(self,nums1:List[int],nums2:List[int]):self.nums1=nums1self.nums2=nums2self.cnt=Counter(nums2)defadd(self,index:int,val:int)->None:old=self.nums2[index]self.cnt[old]-=1self.cnt[old+val]+=1self.nums2[index]+=valdefcount(self,tot:int)->int:returnsum(self.cnt[tot-v]forvinself.nums1)# Your FindSumPairs object will be instantiated and called as such:# obj = FindSumPairs(nums1, nums2)# obj.add(index,val)# param_2 = obj.count(tot)
classFindSumPairs{privateint[]nums1;privateint[]nums2;privateMap<Integer,Integer>cnt=newHashMap<>();publicFindSumPairs(int[]nums1,int[]nums2){this.nums1=nums1;this.nums2=nums2;for(intv:nums2){cnt.put(v,cnt.getOrDefault(v,0)+1);}}publicvoidadd(intindex,intval){intold=nums2[index];cnt.put(old,cnt.get(old)-1);cnt.put(old+val,cnt.getOrDefault(old+val,0)+1);nums2[index]+=val;}publicintcount(inttot){intans=0;for(intv:nums1){ans+=cnt.getOrDefault(tot-v,0);}returnans;}}/** * 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); */
classFindSumPairs{public:FindSumPairs(vector<int>&nums1,vector<int>&nums2){this->nums1=nums1;this->nums2=nums2;for(int&v:nums2){++cnt[v];}}voidadd(intindex,intval){intold=nums2[index];--cnt[old];++cnt[old+val];nums2[index]+=val;}intcount(inttot){intans=0;for(int&v:nums1){ans+=cnt[tot-v];}returnans;}private:vector<int>nums1;vector<int>nums2;unordered_map<int,int>cnt;};/** * 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); */
typeFindSumPairsstruct{nums1[]intnums2[]intcntmap[int]int}funcConstructor(nums1[]int,nums2[]int)FindSumPairs{cnt:=map[int]int{}for_,v:=rangenums2{cnt[v]++}returnFindSumPairs{nums1,nums2,cnt}}func(this*FindSumPairs)Add(indexint,valint){old:=this.nums2[index]this.cnt[old]--this.cnt[old+val]++this.nums2[index]+=val}func(this*FindSumPairs)Count(totint)(ansint){for_,v:=rangethis.nums1{ans+=this.cnt[tot-v]}return}/** * Your FindSumPairs object will be instantiated and called as such: * obj := Constructor(nums1, nums2); * obj.Add(index,val); * param_2 := obj.Count(tot); */