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

响应式网站什么意思网站建设的基本

响应式网站什么意思,网站建设的基本,宝安电子厂做网站,网站的排版设计*注&#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/115746.html

相关文章:

  • 网站建设优化广告流量站长之家备案查询
  • 南宁保洁网站建设百度大数据中心
  • 新疆建设兵团组织部网站好口碑的关键词优化
  • 编程培训机构设计seo外链发布工具
  • 建设什么网站可以赚钱百度官方网站
  • 南充房产网最新房价seo流量是什么
  • 武汉专业外贸网站制作维护torrent种子猫
  • wordpress怎么添加子目录网络优化大师
  • 聊城房地产网站建设广州网站优化外包
  • 网站设计步骤及图解重庆seo
  • 广州市平安建设 网站如何免费注册网站平台
  • 上海门户网站怎么登录如何建立网站平台
  • 网站建设技术jsp课程设计关键词seo排名怎么样
  • 网络 网站建设淘宝seo推广优化
  • 宁德城乡建设部网站首页baidu百度
  • 有那些网站可以做推广昆明网站seo服务
  • 惠州网站建设方案外包西安快速排名优化
  • 网站建设费用计入管理费用的哪个科目seo搜索引擎营销工具
  • 广州外贸b2b网站建设百度风云榜热搜
  • 一站式服务logo设计网站提交入口
  • 中文网站 可以做谷歌推广吗营业推广促销
  • 谁会在掏宝网上做网站站长之家域名查询鹿少女
  • 做资金盘网站违法吗珠海百度seo
  • 银川网站建设多少钱互联网营销案例分析
  • 南山的网站建设广州网络公司
  • 做网站需要掌握的软件sem账户托管公司
  • 网络互联网推广网站seo设计方案案例
  • 免费0代码开发平台百度推广seo
  • 做微博网站好不好江苏seo
  • 网站做镜像的有什么用企业网站制作模板