维护一个字符串,支持以下操作:

 

主要就是 成段插入、成段删除、成段翻转。前两个操作很好通过rope实现。第三个操作也不难,维护两个rope,一个正向,一个反向,翻转时swap一下就行了。
 
rope教程: http://blog.csdn.net/iamzky/article/details/38348653
 
Code(Orz zky):
 #include<cstdio>
#include<ext/rope>
using namespace std;
using namespace __gnu_cxx;
crope a,b,tmp;
int n,p,sz,len,res;
char op[],s[],r[],c;
inline int getint(){res=;c='*';while(c<''||c>'')c=getchar();while(c>=''&&c<=''){res=res*+(c-'');c=getchar();}return res;}
int main()
{
scanf("%d",&n);
for(;n>;n--)
{
scanf("%s",op);
if(op[]=='M')p=getint();
else if(op[]=='P')p--;
else if(op[]=='N')p++;
else if(op[]=='G'){putchar(a[p]);putchar('\n');}
else if(op[]=='I')
{
sz=getint();
len=a.length();
for(int i=;i<sz;i++){
do{s[i]=getchar();}while(s[i]=='\n');
r[sz-i-]=s[i];
}
s[sz]=r[sz]='\0';
a.insert(p,s);
b.insert(len-p,r);
}
else if(op[]=='D')
{
sz=getint();
len=a.length();
a.erase(p,sz);
b.erase(len-p-sz,sz);
}
else if(op[]=='R')
{
sz=getint();
len=a.length();
tmp=a.substr(p,sz);
a=a.substr(,p)+b.substr(len-p-sz,sz)+a.substr(p+sz,len-p-sz);
b=b.substr(,len-p-sz)+tmp+b.substr(len-p,p);
}
}
return ;
}

【rope】bzoj1269 [AHOI2006]文本编辑器editor的更多相关文章

  1. BZOJ1269 [AHOI2006]文本编辑器editor 【82行splay】

    1269: [AHOI2006]文本编辑器editor Time Limit: 10 Sec  Memory Limit: 162 MB Submit: 4633  Solved: 1782 [Sub ...

  2. [bzoj1269][AHOI2006文本编辑器editor] (splay模版题 or pb_ds [rope]大法)

    Description 这些日子,可可不和卡卡一起玩了,原来可可正废寝忘食的想做一个简单而高效的文本编辑器.你能帮助他吗?为了明确任务目标,可可对“文本编辑器”做了一个抽象的定义:   文本:由0个或 ...

  3. Bzoj1269 [AHOI2006]文本编辑器editor

    Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 3678  Solved: 1380 Description 这些日子,可可不和卡卡一起玩了,原来可可正 ...

  4. [BZOJ1269] [AHOI2006] 文本编辑器editor (splay)

    Description 这些日子,可可不和卡卡一起玩了,原来可可正废寝忘食的想做一个简单而高效的文本编辑器.你能帮助他吗?为了明确任务目标,可可对“文本编辑器”做了一个抽象的定义:  文本:由0个或多 ...

  5. BZOJ1269——[AHOI2006]文本编辑器editor

    1.题意:各种splay操作,一道好的模板题2333 2.分析:splay模板题,没啥解释QAQ #include <stack> #include <cstdio> #inc ...

  6. 【BZOJ1269/1507】[AHOI2006]文本编辑器editor Splay

    [BZOJ1269][AHOI2006]文本编辑器editor Description 这些日子,可可不和卡卡一起玩了,原来可可正废寝忘食的想做一个简单而高效的文本编辑器.你能帮助他吗?为了明确任务目 ...

  7. 【bzoj1507】[NOI2003]Editor /【bzoj1269】[AHOI2006]文本编辑器editor Splay

    [bzoj1507][NOI2003]Editor 题目描述 输入 输入文件editor.in的第一行是指令条数t,以下是需要执行的t个操作.其中: 为了使输入文件便于阅读,Insert操作的字符串中 ...

  8. AHOI2006文本编辑器editor

    1269: [AHOI2006]文本编辑器editor Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 1885  Solved: 683[Submit ...

  9. BZOJ 1269: [AHOI2006]文本编辑器editor( splay )

    splay..( BZOJ 1507 题目基本相同..双倍经验 ) ------------------------------------------------------------------ ...

随机推荐

  1. nodejs入门教程之http的get和request简介及应用

    nodejs入门教程之http的get和request简介及应用 前言 上一篇文章,我介绍了nodejs的几个常用的模块及简单的案例,今天我们再来重点看一下nodejs的http模块,关于http模块 ...

  2. HTML跳转新窗口的方法

    笔试遇到这样的一个问题,特意整理一下. 方法一 纯HTML <a href="http://www.cnblogs.com" target="_blank" ...

  3. Python ctypes 在 Python 2 和 Python 3 中的不同 // 使用ctypes过程中问题汇总

    In Python 2.7, strings are byte-strings by default. In Python 3.x, they are unicode by default. Try ...

  4. windows 上启动appium

    import org.apache.commons.exec.CommandLine; import org.apache.commons.exec.DefaultExecuteResultHandl ...

  5. github新建托管项目及上传项目

    一.新建托管项目 1.注册: 2.点击new repositories新建一个新项目: 3.输入项目名称及项目描述,Create repository: 4.点击右边栏的剪切板图标,记录下你的项目地址 ...

  6. PHP路由代码

    <?php /**  * 路由  * @author 角度 QQ:1286522207  *  */ class Dispatcher extends Action {     private ...

  7. python基础===trheading 模块

    '''threading模块''' import threading import time def music(func): for i in range(2): print("[+]i ...

  8. 在64位linux下编译32位程序

    在64位linux下编译32位程序 http://blog.csdn.net/xsckernel/article/details/38045783

  9. C# 读写XML文件示例

    using System; using System.Collections.Generic; using System.Text; using System.Configuration; using ...

  10. Deep Learning基础--CNN的反向求导及练习

    前言: CNN作为DL中最成功的模型之一,有必要对其更进一步研究它.虽然在前面的博文Stacked CNN简单介绍中有大概介绍过CNN的使用,不过那是有个前提的:CNN中的参数必须已提前学习好.而本文 ...