2020牛客国庆集训派对day8 G-Shuffle Cards(扩展STL容器,rope可持久化平衡树)

题目

https://ac.nowcoder.com/acm/contest/7865/G

题意

给你n张牌,要你洗k次牌。
后面k行数据,p,s表示将第p张牌后的s张牌,放到牌顶。
让你求k次操作之后牌的顺序。

题解

这就很明显是个区间插入、删除的操作模拟,可是因为n,k都是1e5的,所以正常用vector写肯定TLE。在这里就需要用到神奇的东西——rope容器。

rope是什么?

rope 不属于标准 STL,属于扩展 STL,来自 pb_ds 库 (Policy-Based Data Structures)

它的头文件:#include<ext/rope> (注:可以打开devcpp的目录去rope这个头文件看看它的操作)

它的名称空间:using namespace __gnu_cxx;

定义方法:rope<变量类型>变量名称;

或    crope 变量名称;

其中crope相当于定义成rope < char >,即定义为string类型

rope 解释

算法解释:块状链表(即讲链表与数组的优势结合,形成分块思想)

用途解释:这本来是一个用于快速操作string的工具,却一般被定义成int,然后用作可持久化线段树!

rope 内部是块状链表实现的,黑科技是支持 O(1) 复制,而且不会空间爆炸 (rope 是平衡树,拷贝时只拷贝根节点就行)。因此可以用来做可持久化数组。
经典的可持久化线段树的图解

支持的操作:

#include <ext/rope>  // 头文件
using namespace __gnu_cxx;  // 注意名称空间rope<int> rp;int main() {rp.push_back(x); // 在末尾插入 xrp.insert(pos, x); // 在 pos 处插入 xrp.erase(pos, x); // 在 pos 处删除 x 个元素rp.length(); // 返回 rp 的大小rp.size(); // 同上rp.replace(pos, x); // 将 pos 处的元素替换成 xrp.substr(pos, x); // 从 pos 处开始提取 x 个元素rp.copy(pos, x, s); // 从 pos 处开始复制 x 个元素到 s 中rp[x]; // 访问第 x 个元素rp.at(x); // 同上return 0;
}

AC 代码

#include <bits/extc++.h>
#include <bits/stdc++.h>
using namespace std;
using namespace __gnu_cxx;
const int N = 100010;int main() {int n, m, a[N] = {0}; cin >> n >> m;for (int i = 0; i < n; i++) a[i] = i + 1;rope<int> rp(a);while (m--) {int p, s; cin >> p >> s; p--;rp.insert(0, rp.substr(p, s));rp.erase(p + s, s);}for (auto i : rp) cout << i << " ";return 0;
}

2020牛客国庆集训派对day8 G-Shuffle Cards(扩展STL容器,rope可持久化平衡树)相关推荐

  1. 2020牛客国庆集训派对day8

    牛客网链接 文章目录 Easy Chess 题意: 题解: Easy Problemset 题意 题解: Shuffle Cards 题解: Diff-prime Pairs 题意 题解: 代码: E ...

  2. 2020牛客国庆集训派对day3 I.Rooted Tree(哈代-拉马努金拆分数列)

    2020牛客国庆集训派对day3 I.Rooted Tree(哈代-拉马努金拆分数列) 题目 https://ac.nowcoder.com/acm/contest/7830/I 题意 给你n个点,问 ...

  3. 2020牛客国庆集训派对day2 补题J

    2020牛客国庆集训派对day2 补题J:VIRUS OUTBREAK 题目描述 The State Veterinary Services Department recently reported ...

  4. 2020牛客国庆集训派对day2 H-STROOP EFFECT(英语题)

    2020牛客国庆集训派对day2 H-STROOP EFFECT(英语题) 题目 https://ac.nowcoder.com/acm/contest/7818/H 题意 这题目真的太难读懂了,赛后 ...

  5. 2020牛客国庆集训派对day1 A.ABB

    2020牛客国庆集训派对day1 A.ABB 题目链接 题目描述 Fernando was hired by the University of Waterloo to finish a develo ...

  6. 2020牛客国庆集训派对day2 F题 Java大数处理

    题目: 链接:https://ac.nowcoder.com/acm/contest/16913/F 来源:牛客网 The following code snippet calculates the ...

  7. 2020牛客国庆集训派对day4 Arithmetic Progressions

    Arithmetic Progressions 链接:https://ac.nowcoder.com/acm/contest/7831/B 来源:牛客网 题目描述 An arithmetic prog ...

  8. 2020牛客国庆集训派对day3 Leftbest

    Leftbest 链接:https://ac.nowcoder.com/acm/contest/7830/A 来源:牛客网 题目描述 Jack is worried about being singl ...

  9. 2020牛客国庆集训派对day2 AKU NEGARAKU

    来源:牛客网: 题目描述 1st Academy is an international leadership training academy based in Kuala Lumpur. Ever ...

最新文章

  1. python数据结构与算法:排序算法(面试经验总结)
  2. mongodb集合的增删
  3. FPGA基础知识极简教程(6)UART通信与移位寄存器的应用
  4. Android蓝牙开发其二
  5. ecshop 属性自动组合_【深度文章】结构设计中的荷载组合剖析(下)
  6. Lotus Notes常见问题答疑
  7. python3.5.3下载安装教程_在Python3.5下安装和测试
  8. 贪心/栈 - 去除重复字母
  9. userscript.user.js 文件头
  10. php查询mysql返回大量数据结果集导致内存溢出的解决方法
  11. 批量部署Linux操作系统的一场革命----Cobbler
  12. oracle中nvarchar2字符集不匹配
  13. linux apache tomcat ajp,Linux下apache tomcat ajp session複製
  14. 在线数值列表求和工具
  15. setUserVisibleHint-- fragment真正的onResume和onPause方法
  16. 欧拉函数之和(51nod 1239)
  17. ppt flash无法播放解决方法
  18. 安装phantomjs、使用phantomjs以及时遇到问题时的解决方法
  19. 句柄(handle)是什么?
  20. 第七章 C语言函数_C语言全局变量和局部变量

热门文章

  1. itop4412上移植360WiFi 二代AP模式
  2. Math.atan2()
  3. Spring Boot项目中集成Elasticsearch,并实现高效的搜索功能
  4. exists和not exists的用法
  5. 你知道旋风图怎么制作吗?这个Excel技巧你一定要知道
  6. [OpenAirInterface实战-11] :OAI nr-softmodem命令行参数详解
  7. 表达式计算器 ExpressionRunner
  8. 高级java工程师周末班,西安java工程师培训周末班
  9. 字节8年测试开发工程师感悟,说说我们自动化测试平台的进阶之路
  10. 微服务的灵魂摆渡者——Nacos,来一篇原理全攻略