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

响应式网站什么意思综合型b2b电子商务平台网站

响应式网站什么意思,综合型b2b电子商务平台网站,腾讯企业邮箱二维码登录,学校电脑课做网站的软件*注&#xff1a;代码和题解思路来源于灵茶山艾府&#xff0c;因为我之前未接触过vector<pair<>>与map的联合使用才写的笔记 链接&#xff1a;灵茶山艾府题解 核心思路&#xff1a;建立 unordered_map<int, vector<pair<int, int>>> history; …

*注:代码和题解思路来源于灵茶山艾府,因为我之前未接触过vector<pair<>>与map的联合使用才写的笔记  链接:灵茶山艾府题解

核心思路:建立 unordered_map<int, vector<pair<int, int>>> history;  令key为下标 vector存放不同快照引索的值,详看下文的输出

 unordered_map<int, vector<pair<int, int>>> history; 

键:int 

值:vector<pair<int, int>>

history[0] 会访问 history 中键为 0 所对应的 std::vector<std::pair<int, int>>。如果该键不存在,会自动创建一个空的 vector。



// 正确访问方式
    if (!history[0].empty()) {
        int firstValue = history[0][0].first;  10
        int secondValue = history[0][0].second;  20
}


在代码里,使用 history[0].emplace_back(10, 20); 向 history 中键为 0 对应的 vector 里"插入"了一个 std::pair<int, int> 对象,其值为 (10, 20)。

emplace_back(10, 20) 会在这个 vector 的末尾直接构造一个 std::pair<int, int> 对象,这个对象的第一个元素是 10,第二个元素是 20。

  history[0].emplace_back(10, 20);
    history[0].emplace_back(30, 40);
    history[1].emplace_back(50, 60);

unordered_map数组的状态

key=index是下标题目说的下标
Key: 0
  (10, 20)history[key][0]  history[index][0].first --10快照索引  history[index][0].second--20
  (30, 40)history[key][0]
Key: 1
  (50, 60)

代码分析:

 int j = ranges::lower_bound(h, pair(snap_id + 1, 0)) - h.begin() - 1;
                中 pair(snap_id + 1, 0)
        假设 h 中有如下元素:
std::vector<std::pair<int, int>> h = { {10, 20}, {30, 40}, {50, 60} };

若 snap_id 为 20,那么 std::pair(snap_id + 1, 0) 就是 std::pair(21, 0)。
std::ranges::lower_bound 算法会依据 std::pair 的第一个元素进行比较,找到第一个大于等于 21 的元素,也就是 (30, 40)。
在这个过程中,std::pair 的第二个元素 0 并不影响查找结果,它只是占位,保证 std::pair 类型的完整性。

class SnapshotArray {unordered_map<int,vector<pair<int, int>>> history; int c_snap_id=0;
public:SnapshotArray(int length) {}void set(int index, int val) {history[index].emplace_back(c_snap_id,val);}int snap() {return c_snap_id++;}int get(int index, int snap_id) {auto &h=history[index];int j=ranges::lower_bound(h,pair(snap_id+1,0))-h.begin()-1;return j>=0?h[j].second:0;}
};/*** Your SnapshotArray object will be instantiated and called as such:* SnapshotArray* obj = new SnapshotArray(length);* obj->set(index,val);* int param_2 = obj->snap();* int param_3 = obj->get(index,snap_id);*/

http://www.dtcms.com/wzjs/138696.html

相关文章:

  • logo设计在线生成免费版seo文章
  • 怎么做网站扩展搜索引擎优化的缺点包括
  • python做网站php百度推广托管
  • 网站设计制作电话多少如何做好市场推广
  • 做网管要维护网站百度推广登录网站
  • 做响应式网站的微博号百度指数在线查询工具
  • 中国最大免费h5游戏源码网站百度本地惠生活推广
  • 网站 做购物车网络推广哪家好
  • 镇江网站建设哪家好竞价推广账户竞价托管
  • 长春关键词seo价格seo优化员
  • 网站备案核验点 上海长尾词seo排名
  • 网站建设方面的免费创建网站软件
  • 石家庄网络建站福州网站排名推广
  • 做货代在哪个网站找客源百度seo排名报价
  • 浙江企业在线河南seo排名
  • 网站建设费计入哪个二级科目惠州seo快速排名
  • 品牌好的佛山网站建设价格银徽seo
  • 网站里的内容都是什么作用不受限制的搜索浏览器
  • 建设工程挂网是在那个网站国内专业的seo机构
  • 湛江人做寄生虫网站百度热搜大数据
  • 广州网站建设 推广公司百度快速优化推广
  • 做网站容易还是app容易百度知道提问首页
  • 做室内效果图网站seo北京优化
  • 怎么用记事本做网站仿站定制模板建站
  • 南充做网站略奥网络九易建网站的建站流程
  • 网站需要哪些东西关键词筛选工具
  • 济南网站建设代码网站优化资源
  • 建设完网站如何信息更新对网站进行seo优化
  • 新乡商城网站建设云南疫情最新数据消息中高风险地区
  • 网站评估 源码如何做营销策划方案