UVALive 6145 Version Controlled IDE(可持久化treap、rope)
2015-02-02 23:50
357 查看
题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=4156
题目拷贝难度大我就不复制了。
题目大意:维护一个字符串,要求支持插入、删除操作,还有输出第 i 次操作后的某个子串。强制在线。
思路1:使用可持久化treap可破,详细可见CLJ的《可持久化数据结构的研究》。
思路2:rope大法好,详见:http://blog.csdn.net/guognib/article/details/20563453(文档:http://www.sgi.com/tech/stl/Rope.html),代码短速度快,可惜不能打lazy标记。
PS:自从学了函数式编程,发现可持久化什么的都变简单了。
PS:不用智能指针只要845MS。这真是一个大坑。本来我换成普通指针只是想用于调试……
PS:UVALive居然不保存代码!于是我又去vjudge交了一次。
代码(C++11 2116MS):
View Code
题目拷贝难度大我就不复制了。
题目大意:维护一个字符串,要求支持插入、删除操作,还有输出第 i 次操作后的某个子串。强制在线。
思路1:使用可持久化treap可破,详细可见CLJ的《可持久化数据结构的研究》。
思路2:rope大法好,详见:http://blog.csdn.net/guognib/article/details/20563453(文档:http://www.sgi.com/tech/stl/Rope.html),代码短速度快,可惜不能打lazy标记。
PS:自从学了函数式编程,发现可持久化什么的都变简单了。
PS:不用智能指针只要845MS。这真是一个大坑。本来我换成普通指针只是想用于调试……
PS:UVALive居然不保存代码!于是我又去vjudge交了一次。
代码(C++11 2116MS):
#include <bits/stdc++.h> #include <ext/rope> using namespace std; #define FOR(i, n) for(int i = 0; i < n; ++i) const int MAXN = 50010; const int MAXS = 200010; __gnu_cxx::crope rt[MAXN], tmp; char s[MAXS]; int m, vnow, d; int main() { scanf("%d", &m); while(m--) { int op, p, v, c; scanf("%d", &op); if(op == 1) { scanf("%d%s", &p, s); p -= d; rt[vnow + 1] = rt[vnow]; rt[++vnow].insert(p, s); } else if(op == 2) { scanf("%d%d", &p, &c); p -= d, c -= d; rt[vnow + 1] = rt[vnow]; rt[++vnow].erase(p - 1, c); } else if(op == 3) { scanf("%d%d%d", &v, &p, &c); v -= d, p -= d, c -= d; tmp = rt[v].substr(p - 1, c); printf("%s\n", tmp.c_str()); d += count(tmp.begin(), tmp.end(), 'c'); } } }
View Code
相关文章推荐
- UVA 12538 Version Controlled IDE(可持久化treap)
- uva12538 Version Controlled IDE(可持续化Treap * 模板, STL ext/rope(块状链表))
- 【treap】6145 - Version Controlled IDE 2012合艾赛区E题
- UVA12538 Version Controlled IDE (可持久化Treap)
- UVA 12538 Version Controlled IDE 可持久化平衡树 || rope
- UVAL 6145 Version Controlled IDE
- UVA 12538 Version Controlled IDE 解题报告
- Version Controlled IDE_块状链表_ext/rope_2018_2_19
- UVA 12538 Version Controlled IDE
- UVA 12538 Version Controlled IDE 解题报告
- [UVA12538]Version Controlled IDE && 可持久化treap
- uva live 5031 Graph and Queries(Treap x 并查集)
- UVaLive 5031 Graph and Queries (Treap)
- [UVa12538]Version Controlled IDE
- UvaLive 5031 Graph and Queries(Treap+并查集)
- UVALive 5031 Graph and Queries (Treap)
- UVALive 5031 Graph and Queries(离线,treap)
- 【可持久化平衡树】Version Controlled IDE
- 【UVALive】5031 Graph and Queries treap实现名次树
- UVAlive 5031 Graph and Queries(treap)