【rope】bzoj1269 [AHOI2006]文本编辑器editor
2014-09-06 15:41
281 查看
维护一个字符串,支持以下操作:
![](http://img2.ph.126.net/xqYlJ7sau25DeN6qpHzsfg==/6608799356701654823.jpg)
![](http://img0.ph.126.net/rwA2SZZ1HFDKiz9TkvjC5g==/6619096283095419384.jpg)
主要就是 成段插入、成段删除、成段翻转。前两个操作很好通过rope实现。第三个操作也不难,维护两个rope,一个正向,一个反向,翻转时swap一下就行了。
rope教程: http://blog.csdn.net/iamzky/article/details/38348653
Code(Orz zky):
![](http://img2.ph.126.net/xqYlJ7sau25DeN6qpHzsfg==/6608799356701654823.jpg)
![](http://img0.ph.126.net/rwA2SZZ1HFDKiz9TkvjC5g==/6619096283095419384.jpg)
主要就是 成段插入、成段删除、成段翻转。前两个操作很好通过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[21],s[2000001],r[2000001],c; inline int getint(){res=0;c='*';while(c<'0'||c>'9')c=getchar();while(c>='0'&&c<='9'){res=res*10+(c-'0');c=getchar();}return res;} int main() { scanf("%d",&n); for(;n>0;n--) { scanf("%s",op); if(op[0]=='M')p=getint(); else if(op[0]=='P')p--; else if(op[0]=='N')p++; else if(op[0]=='G'){putchar(a[p]);putchar('\n');} else if(op[0]=='I') { sz=getint(); len=a.length(); for(int i=0;i<sz;i++){ do{s[i]=getchar();}while(s[i]=='\n'); r[sz-i-1]=s[i]; } s[sz]=r[sz]='\0'; a.insert(p,s); b.insert(len-p,r); } else if(op[0]=='D') { sz=getint(); len=a.length(); a.erase(p,sz); b.erase(len-p-sz,sz); } else if(op[0]=='R') { sz=getint(); len=a.length(); tmp=a.substr(p,sz); a=a.substr(0,p)+b.substr(len-p-sz,sz)+a.substr(p+sz,len-p-sz); b=b.substr(0,len-p-sz)+tmp+b.substr(len-p,p); } } return 0; }
相关文章推荐
- bzoj1269: [AHOI2006]文本编辑器editor rope
- BZOJ 1269: [AHOI2006]文本编辑器editor 分离合并Splay
- BZOJ 1269: [AHOI2006]文本编辑器editor (splay tree)
- bzoj 1269 [AHOI2006]文本编辑器editor 块状链表
- BZOJ1269: [AHOI2006]文本编辑器editor
- 【bzoj1269】【AHOI2006】文本编辑器editor【Splay】
- bzoj 1269 [AHOI2006]文本编辑器editor
- [NOI2003]Editor & [AHOI2006]文本编辑器editor BZOJ1507&BZOJ1269
- bzoj1269【AHOI2006】文本编辑器editor
- bzoj1269: [AHOI2006]文本编辑器editor
- 【BZOJ】【1269】【AHOI2006】文本编辑器editor
- BZOJ 1269 [AHOI2006]文本编辑器editor 伸展树splay
- bzoj1269 [AHOI2006]文本编辑器editor
- 【bzoj1269】[AHOI2006]文本编辑器editor
- BZOJ 1269: [AHOI2006]文本编辑器editor Splay
- BZOJ_1269&&1507_[AHOI2006]文本编辑器editor&&[NOI2003]Editor
- BZOJ1269 [AHOI2006]文本编辑器editor 【82行splay】
- BZOJ1269 [AHOI2006]文本编辑器editor 【82行splay】
- [bzoj1269][AHOI2006]文本编辑器editor
- 【BZOJ】1269: [AHOI2006]文本编辑器editor(Splay)