当前位置: 首页 > wzjs >正文

微起点网站怎么设置的黄页网站推广服务

微起点网站怎么设置的,黄页网站推广服务,用网站素材做logo,独立网站怎么建设1865. 找出和为指定值的下标对 给你两个整数数组 nums1 和 nums2 ,请你实现一个支持下述两类查询的数据结构: 累加 ,将一个正整数加到 nums2 中指定下标对应元素上。计数 ,统计满足 nums1[i] nums2[j] 等于指定值的下标对 (i, …

1865. 找出和为指定值的下标对

给你两个整数数组 nums1nums2 ,请你实现一个支持下述两类查询的数据结构:

  1. 累加 ,将一个正整数加到 nums2 中指定下标对应元素上。
  2. 计数 ,统计满足 nums1[i] + nums2[j] 等于指定值的下标对 (i, j) 数目(0 <= i < nums1.length0 <= j < nums2.length)。
    实现 FindSumPairs 类:
  • FindSumPairs(int[] nums1, int[] nums2) 使用整数数组 nums1nums2 初始化 FindSumPairs 对象。
  • void add(int index, int val)val 加到 nums2[index] 上,即,执行 nums2[index] += val
  • int count(int tot) 返回满足 nums1[i] + nums2[j] == tot 的下标对 (i, j) 数目。
    示例:
    输入:
["FindSumPairs", "count", "add", "count", "count", "add", "add", "count"]
[[[1, 1, 2, 2, 2, 3], [1, 4, 5, 2, 5, 4]], [7], [3, 2], [8], [4], [0, 1], [1, 1], [7]]

输出:

[null, 8, null, 2, 1, null, null, 11]

解释:
FindSumPairs findSumPairs = new FindSumPairs([1, 1, 2, 2, 2, 3], [1, 4, 5, 2, 5, 4]);
findSumPairs.count(7); // 返回 8 ; 下标对 (2,2), (3,2), (4,2), (2,4), (3,4), (4,4) 满足 2 + 5 = 7 ,下标对 (5,1), (5,5) 满足 3 + 4 = 7
findSumPairs.add(3, 2); // 此时 nums2 = [1,4,5,4,5,4]
findSumPairs.count(8); // 返回 2 ;下标对 (5,2), (5,4) 满足 3 + 5 = 8
findSumPairs.count(4); // 返回 1 ;下标对 (5,0) 满足 3 + 1 = 4
findSumPairs.add(0, 1); // 此时 nums2 = [2,4,5,4,5,4]
findSumPairs.add(1, 1); // 此时 nums2 = [2,5,5,4,5,4]
findSumPairs.count(7); // 返回 11 ;下标对 (2,1), (2,2), (2,4), (3,1), (3,2), (3,4), (4,1), (4,2), (4,4) 满足 2 + 5 = 7 ,下标对 (5,3), (5,5) 满足 3 + 4 = 7
提示:

  • 1 <= nums1.length <= 1000
  • 1 <= nums2.length <= 10^5
  • 1 <= nums1[i] <= 10^9
  • 1 <= nums2[i] <= 10^5
  • 0 <= index < nums2.length
  • 1 <= val <= 10^5
  • 1 <= tot <= 10^9
  • 最多调用 addcount 函数各 1000

思路

注意,nums1和nums2的长度范围是不一样的,nums1很短,我们可以利用这个特点,遍历nums1,和nums2的counter,这样不会超时

type FindSumPairs struct {  nums1 []int       // nums1.length <= 1000  nums2 []int       // nums2.length <= 10e6  cnt2  map[int]int // counter of nums2  
}  func Constructor(nums1 []int, nums2 []int) FindSumPairs {  var cnt2 = make(map[int]int)  for _, x := range nums2 {  cnt2[x]++  }  return FindSumPairs{nums1, nums2, cnt2}  
}  func (this *FindSumPairs) Add(index int, val int) {  this.cnt2[this.nums2[index]]--  this.nums2[index] += val  this.cnt2[this.nums2[index]]++  
}  func (this *FindSumPairs) Count(tot int) int {  var res int  for _, x := range this.nums1 {  res += this.cnt2[tot-x]  }  return res  
}  /**  * Your FindSumPairs object will be instantiated and called as such: * obj := Constructor(nums1, nums2); * obj.Add(index,val); * param_2 := obj.Count(tot); */

也可以把nums1和nums2都转为counter

type FindSumPairs struct {  nums1 []int       // nums1.length <= 1000  nums2 []int       // nums2.length <= 10e6  cnt1  map[int]int // counter of nums1  cnt2  map[int]int // counter of nums2  
}  func Constructor(nums1 []int, nums2 []int) FindSumPairs {  var cnt1 = make(map[int]int)  var cnt2 = make(map[int]int)  for _, x := range nums2 {  cnt2[x]++  }  for _, x := range nums1 {  cnt1[x]++  }  return FindSumPairs{nums1, nums2, cnt1, cnt2}  
}  func (this *FindSumPairs) Add(index int, val int) {  this.cnt2[this.nums2[index]]--  this.nums2[index] += val  this.cnt2[this.nums2[index]]++  
}  func (this *FindSumPairs) Count(tot int) int {  var res int  for k, v := range this.cnt1 {  res += v * (this.cnt2[tot-k])  }  return res  
}
http://www.dtcms.com/wzjs/286026.html

相关文章:

  • 村级网站建设 不断增强创建网址链接
  • 国外b2b网站大全广西网络优化seo
  • 重庆建网站公司深圳百度seo优化
  • 用dw做的网站怎样弄上网上天猫seo搜索优化
  • 北京网站关键词优化公查排名的软件有哪些
  • 简述建设政府门户网站原因全球最大的磁力搜索引擎
  • 网站免费推广计划南昌seo
  • wordpress图片音乐主题成都网站seo外包
  • 收录网站宁波seo优化服务
  • seo网站推广优化网络营销策略内容
  • 学java做网站重庆百度推广
  • 集团高端网站备案查询站长工具
  • 品牌网站建设 意义优化网站的意思
  • 求一个全部用div做的网站百度搜索排名与点击有关吗
  • 金融中介做网站需要seo网站推广培训
  • 手机网站怎么做301百度网页版主页
  • 连云港网站建设费用百度竞价运营
  • 商城网站的运营bt磁力链好用的引擎
  • 建设银行官方网站打不开百度河南代理商
  • 邹平做网站公众号免费推广平台
  • 网站建设属于淘宝哪种类目广东知名seo推广多少钱
  • 阳江市建设路龙源学校网站舆情分析报告案例
  • 施工企业安全文明施工费取费优化网哪个牌子好
  • 网站怎么做免费推广网站建设的基本
  • 如何做软件开发重庆seo优化效果好
  • 商城网站怎么自己搭建b站推广入口2023
  • 建网站多少钱?阿里云盘资源搜索引擎
  • 专业房产网站建设爱网站关键词挖掘工具
  • 杭州做网站的优质公司哪家好wifi优化大师下载
  • photoshop+做网站logo国外搜索网站排名