rope是stl封装好的可持久平衡树(不支持kth)。
基本操作(函数)比较少。
下标从0开始。
{1,2,5,4}.insert(1,10)=>{1,10,2,5,4}

#include<ext/rope>///头文件
using namespace __gnu_cxx;
rope <int> x;
int main(){x.push_back(x); //在末尾加xx.insert(pos, x); //在pos位置加入xx.erase(pos, x); //从pos位置删除x个元素x.copy(pos, len, x); //从pos开始len个元素用x代替x.replace(pos, x); //从pos开始全部换为xx.substr(pos, x); //提取pos开始x个元素x.at(i);x[i]; //访问第x个元素return 0;
}

1.

rope< int>相当于一个块状链表。可以用substr等函数实现区间处理。引用一下别人的代码:

#include<bits/stdc++.h>
#include<ext/rope>
using namespace std;
using namespace __gnu_cxx;
typedef long long LL;
const int inf = 0x3f3f3f3f;
const int N = 100005;int main()
{int n,m;while(~scanf("%d %d",&n,&m)){rope<int> str;for(int i = 0;i < n;++i)str.push_back(i + 1);for(int i = 0;i < m;++i){int a,b;scanf("%d %d",&a,&b);str = str.substr(a - 1,b) + str.substr(0,a - 1) + str.substr(a + b - 1,n - a - b + 1);//好像是根号复杂度}for(int i = 0;i < n;++i){if(i == n - 1){printf("%d\n",str[i]);}else{printf("%d ",str[i]);}}}return 0;
}

也可以去水 文本编辑器 那题。

2.

如果是rope< char>,相当于一个重型string。可以cout;可以+=。

3.

最大的特点是支持可持久化。
rope可以o(1)继承上一个版本。(内部维护了平衡树的指针)
写法如下:s[i]=new auto(*s[i-1]);
用于模拟可持久栈:
可持久化栈

#include <bits/stdc++.h>
#include <ext/rope>
using namespace std;
using namespace __gnu_cxx;
//-----pre_def----
const double PI = acos(-1.0);
const int INF = 0x3f3f3f3f;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef pair<double, double> PDD;
#define fir(i, a, b) for (int i = (a); i <= (b); i++)
#define rif(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
#define init_h memset(h, -1, sizeof h), idx = 0;
#define lowbit(x) x &(-x)//---------------
const int N = 8e4 + 10;
rope<int> *s[N];
void init() {}
int main()
{#ifndef ONLINE_JUDGEfreopen("in.txt", "r", stdin);freopen("out.txt", "w", stdout);int StartTime = clock();
#endifs[0] = new rope<int>(-1);int m, x;char op[5];scanf("%d", &m);fir(i, 1, m){s[i] = new auto(*s[i - 1]);scanf("%s", op);if (*op != 's')scanf("%d", &x);elses[i]->pop_back();if (*op == 'a')s[i]->push_back(x);if (*op == 't')s[i] = s[x - 1];printf("%d\n", s[i]->at(s[i]->size() - 1));}
#ifndef ONLINE_JUDGEprintf("Run_Time = %d ms\n", clock() - StartTime);
#endifreturn 0;
}

参考:Ryan_<

c++ STL rope小结相关推荐

  1. 块状链表(STL rope)

    块状链表(STL rope) 首先介绍一下块状链表. 我们都知道: 数组 具有 O(1)的查询时间,O(N)的删除,O(N)的插入. 链表 具有 O(N)的查询时间,O(1)的删除,O(1)的插入. ...

  2. 【Rope大法好】【STL中丧心病狂的可持久化平衡树】

    曾经我不会写平衡树--于是在STL中乱翻--学到了pb_ds库中的SXBK的斐波那契堆.支持kth的set,和--ext/rope 先发一个官方的 说明 (鸣谢maoxiaohan1999): htt ...

  3. STL - bitset

    STL - bitset 小结 声明: #include <bitset> using std::bitset; 申请对象以及初始化: bitset<n> b; b有n位,每位 ...

  4. [STL]六大组件介绍(目录 全)

    一般介绍 STL(Standard TemplateLibrary),即标准模板库,是一个具有工业强度的,高效的C++程序库.它被容纳于C++标准程序库(C++ Standard Library)中, ...

  5. 一些鲜为人知却非常实用的数据结构 - Haippy

    原文:http://www.udpwork.com/item/9932.html 作为程序猿(媛),你必须熟知一些常见的数据结构,比如栈.队列.字符串.链表.二叉树.哈希,但是除了这些常见的数据结构以 ...

  6. 《C++性能优化指南》 linux版代码及原理解读 第四章

    目录 概述 为什么字符串很麻烦 字符串是动态分配的 字符串赋值背后的操作 如何面对字符串会进行大量复制 写时复制COW(copy on write) 尝试优化字符串 避免临时字符串 通过预留存储空间减 ...

  7. ACM比赛经验、刷题记录及模板库总结(更新中)

    前言 本文所提及的部分题目代码,可以在我的Github上找到 第一部分 经验分享及感受 第二部分 刷题记录 一.基础算法&程序语言 //strlen()函数的复杂度是O(n)要小心 //截取字 ...

  8. 判断出栈顺序是否正确

    先说一下题目: 假设有一个栈S,每次我们可以把序列A(含N个元素)中的第一个元素移入栈S,也可以是从栈顶弹出一个元素放入出栈序列B.这 样,经过N次入栈和出栈操作后,我们可以得到一个出栈序列B. 现在 ...

  9. 视觉SLAM十四讲笔记 -- 第一讲

    ​ 第一讲:课后习题 有线性方程 Ax = b,若已知 A,b,需要求解x,该如何求解? 这对 A 和 b 有哪些要求? [提示:从A的维度和秩角度来分析] 答:可以利用大学时候学的非齐次方程组的方法 ...

最新文章

  1. Linux(CentOS)安装配置zeromq、jzmq(解决各种问题)
  2. 重装系统找不到固态_重装系统时找不到固态
  3. leetcode算法题--树的子结构
  4. 对python里的装饰器
  5. Android输出签名的 SHA1 值
  6. python打开文件_喜大普奔 | 如何在Win10下利用Python打开grib文件
  7. IOS15瀑布流的使用
  8. 有36匹马,六个跑道。没有记时器等设备,用最少的比赛次数算出跑的最快的前3匹马
  9. StarTeam 使用小记
  10. 基于ECharts+百度地图开发散点扩散图
  11. 循环冗余校验 使用及记忆方法
  12. Maven For Mac下的环境搭建
  13. Gridview DetailView
  14. c语言有趣小程序,c语言小程序代码大全(9个经典的C语言小程序)
  15. java 加密 压缩_如何用java 将文件加密压缩为zip文件.
  16. AMD显卡更新UEFI GOP
  17. 惠普暗影精灵8和惠普暗影精灵8 Plus 评测
  18. 移动互联网时代必读十大图书
  19. 「爬虫教程」吐血整理,最详细的爬虫入门教程
  20. Local Storage和Session Storage详解

热门文章

  1. uniapp 微信小程序使用antv f2图标库
  2. 福田区卫生局社区信息平台
  3. 【Keras之父】DL用于Text
  4. MybatisPlus引用BaseMapper中的方法报错: BindingException: Invalid bound statement (not found):
  5. 《数据结构 》排序试题附答案
  6. 超简单正则表达式入门教程
  7. C语言解读assert函数
  8. 使用photoView完成照片查看器(网络图片)
  9. c语言反汇编过程,利用反汇编手段解析C语言函数
  10. 【笑话:】执子之手,方知子丑,泪流满面,子不走我走。爆笑死你我不负责~~~~[