• 【rope】bzoj1269 [AHOI2006]文本编辑器editor


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

     
    【rope】bzoj1269 [AHOI2006]文本编辑器editor - AutSky_南北組UP - AutSky_JadeK’s Codes

    【rope】bzoj1269 [AHOI2006]文本编辑器editor - AutSky_南北組UP - AutSky_JadeK’s Codes
     

    主要就是 成段插入、成段删除、成段翻转。前两个操作很好通过rope实现。第三个操作也不难,维护两个rope,一个正向,一个反向,翻转时swap一下就行了。
     
    rope教程: http://blog.csdn.net/iamzky/article/details/38348653
     
    Code(Orz zky):
     1 #include<cstdio>
     2 #include<ext/rope>
     3 using namespace std;
     4 using namespace __gnu_cxx;
     5 crope a,b,tmp;
     6 int n,p,sz,len,res;
     7 char op[21],s[2000001],r[2000001],c;
     8 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;}
     9 int main()
    10 {
    11     scanf("%d",&n);
    12     for(;n>0;n--)
    13       {
    14           scanf("%s",op);
    15           if(op[0]=='M')p=getint();
    16           else if(op[0]=='P')p--;
    17         else if(op[0]=='N')p++;
    18           else if(op[0]=='G'){putchar(a[p]);putchar('
    ');}
    19           else if(op[0]=='I')
    20             {
    21                 sz=getint();
    22                 len=a.length();
    23                 for(int i=0;i<sz;i++){
    24                   do{s[i]=getchar();}while(s[i]=='
    ');
    25                   r[sz-i-1]=s[i];
    26                 }
    27             s[sz]=r[sz]='';
    28             a.insert(p,s);
    29             b.insert(len-p,r);
    30             }
    31           else if(op[0]=='D')
    32             {
    33               sz=getint();
    34             len=a.length();
    35             a.erase(p,sz);
    36             b.erase(len-p-sz,sz);
    37             }
    38           else if(op[0]=='R')
    39             {
    40                 sz=getint();
    41             len=a.length();
    42             tmp=a.substr(p,sz);
    43             a=a.substr(0,p)+b.substr(len-p-sz,sz)+a.substr(p+sz,len-p-sz);
    44             b=b.substr(0,len-p-sz)+tmp+b.substr(len-p,p);
    45             }
    46       }
    47     return 0;
    48 }
    ——The Solution By AutSky_JadeK From UESTC 转载请注明出处:http://www.cnblogs.com/autsky-jadek/
  • 相关阅读:
    2006: [NOI2010]超级钢琴
    3640: JC的小苹果
    2005: [Noi2010]能量采集
    金蝶云星空修改密码策略的SQL脚本
    关于 springboot 过滤器中使用@Autowired 为空 以及 使用 @Value 无法读取yml配置的问题解决
    CAS .NET Client 循环重定向的解决办法
    K/3 Cloud SSO配置
    K/3 Cloud SSO配置答疑
    K/3 Cloud 元数据表
    AngularJS select中ngOptions用法详解【转】
  • 原文地址:https://www.cnblogs.com/autsky-jadek/p/3959455.html
Copyright © 2020-2023  润新知