ROPE
#include <ext/rope>
using namespace __gnu_cxx;
int a[];
rope<int> x;
rope<int> x(a,a + n);
rope<int> a(x); x->at(); //cout<<x->at(10)<<endl;
x[];
x->push_back(x) // 在末尾添加x
x->insert(pos,x) // 在pos插入x
x->erase(pos,x) // 从pos开始删除x个
x->replace(pos,x) // 从pos开始换成x
x->substr(pos,x) // 提取pos开始x个
描述 给一个空数列,有M次操作,每次操作是以下三种之一: ()在数列后加一个数 ()求数列中某位置的值
撤销掉最后进行的若干次操作(1和3)
输入 第一行一个正整数M。
接下来M行,每行开头是一个字符,若该字符为’A’,则表示一个加数操作,接下来一个整数x,表示在数列后加一个整数x;若该字符为’Q’,则表示一个询问操作,接下来一个整数x,表示求x位置的值;若该字符为’U’,则表示一个撤销操作,接下来一个整数x,表示撤销掉最后进行的若干次操作。
输出 对每一个询问操作单独输出一行,表示答案。
样例输入 A
A
A
Q
U
A
Q
U
Q
样例输出 提示 <=M<=^
#include<bits/stdc++.h>
#include<ext/rope>
using namespace std;
using namespace __gnu_cxx;
rope<int> *now[];
void print(rope<int> s)
{
for (int i = ; i < s.length(); i++)
{
cout << s[i] << " ";
}
cout << endl;
}
int cnt = ;
int main()
{
now[] = new rope<int>();
//cout << now[0] << endl;
int n, m;
cin >> m;
//print(*now[0]);
char ch;
int x;
for (int i = ; i <= m; i++)
{
//now[i] = new rope<int>(*now[i - 1]);
cin >> ch >> x;
if (ch == 'A')
{
++cnt;
now[cnt] = new rope<int>(*now[cnt - ]);
now[cnt]->push_back(x);
}
else if (ch == 'Q')
{
cout << now[cnt]->at(x-) << endl;
}
else if (ch == 'U')
{
++cnt;
now[cnt] = new rope<int>(*now[cnt - - x]);
}
print(*now[cnt]);
}
}
ROPE的更多相关文章
- [bzoj3673][可持久化并查集 by zky] (rope(可持久化数组)+并查集=可持久化并查集)
Description n个集合 m个操作 操作: 1 a b 合并a,b所在集合 2 k 回到第k次操作之后的状态(查询算作操作) 3 a b 询问a,b是否属于同一集合,是则输出1否则输出0 0& ...
- 谈c++ pb_ds库(一)rope大法好
参考资料 1)官方说明 支持 sorry,cena不支持rope 声明 1)头文件 #include<ext/rope> 2)调用命名空间 using namespace __gnu_cx ...
- [bzoj1269][AHOI2006文本编辑器editor] (splay模版题 or pb_ds [rope]大法)
Description 这些日子,可可不和卡卡一起玩了,原来可可正废寝忘食的想做一个简单而高效的文本编辑器.你能帮助他吗?为了明确任务目标,可可对“文本编辑器”做了一个抽象的定义: 文本:由0个或 ...
- ural 1145. Rope in the Labyrinth
1145. Rope in the Labyrinth Time limit: 0.5 secondMemory limit: 64 MB A labyrinth with rectangular f ...
- UVALive 6145 Version Controlled IDE(可持久化treap、rope)
题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_ ...
- uva11922(强行用rope替代spaly)
spaly没学过,用rope水过, rope是extension库中的东西,codeblocks编译器支持, 需要包含 #include <ext/rope>using namespace ...
- STL rope
rope的部分简单操作 函数 功能 push_back(x) 在末尾添加x insert(pos,x) 在pos插入x erase(pos,x) 从pos开始删除x个 replace(pos,x) 从 ...
- 牛客网多校第3场C-shuffle card 平衡树或stl(rope)
链接:https://www.nowcoder.com/acm/contest/141/C 来源:牛客网 题目描述 Eddy likes to play cards game since there ...
- Rope整理(可持久化神器)
rope是什么?STL的内置的可持久化的数组.其最为方便的就是可以O1复制原来的数组.事实上rope的内置实现也是平衡树,由于只需要复制根结点,O1可以做到复制历史版本. 然而这个东西常数特大,不开O ...
- 2018 “百度之星”程序设计大赛 - 初赛(A)度度熊学队列 list rope
c++ list使用 #include <cstdio> #include <cstdlib> #include <cmath> #include <cstr ...
随机推荐
- leetcode 148排序链表
优先队列容器,使用小顶堆排序:timeO(nlogn) spaceO(n) /** * Definition for singly-linked list. * struct ListNode { * ...
- sqlalchemy.exc.StatementError: (sqlalchemy.exc.InvalidRequestError) Can't reconnect until invalid transaction is rolled back
从这段话获得灵感 重新启动flask shell之后就好了
- 阶段3 3.SpringMVC·_02.参数绑定及自定义类型转换_1 请求参数绑定入门
请求参数的绑定 参数绑定 创建新的页面 给方法加上注解 前面没有斜线 重新部署项目 传递一个username的值 后台方法接收 重新部署项目 再传一个password的值 再输出password ja ...
- java:Oracle(级联删除,左右内外交叉自然连接,子查询,all,any,in)
1.级联删除: -- 级联删除:裁员,公司倒闭 -- 级联删除(cascade),设置为null(setnull),放任不管(No action) -- cascade:(以一对多为例)如果删除多的一 ...
- ca认证(https)
证书签名过程: 1.网页服务器生成证书请求文件: 2.认证中心确认申请者的身份真实性: 3.认证中心使用根证书的私钥加密证书请求文件,生成证书: 4.把证书传给申请者. 一.实验环境 node1 19 ...
- 服务器上安装并使用tensorboard
需求: 在ubunu16.0的服务器上使用Pytorch内嵌的tensorboard 安装 pip install tensorflow pip install tensorboardX 如果嫌慢可以 ...
- 关于Eclipse及JDK安装过程中的一些问题
一,环境变量的配置 1.配置CLASSPATH系统变量 CLASSPATH系统变量为类查找路径 ①.在使用javac进行编译时遇到import时候就会通过这个变量里面配置的路径去查找.如果配置的是目录 ...
- spring boot-3.原理探究
新建的项目结构如下图: 1.POM 文件 项目会默认依赖 spring-boot-starter-parent 项目 <parent> <groupId>org.springf ...
- Linux-usermod:增加已建立用户的用户组
usermod --help -g, --gid GROUP force use GROUP as new primary group -G, --groups GROUPS new list of ...
- Luogu P2839 [国家集训队]middle
题目 首先我们考虑解决中位数一类问题的常用手段:二分\(mid\),将大于等于它的设为\(1\),小于它的设为\(−1\),判断区间和是否\(\ge0\). 对于询问\(a,b,c,d\),二分完\( ...