zoukankan      html  css  js  c++  java
  • 数据结构:Rope

    以BZOJ1507为例,这里仅仅展示动态区间问题的一些典型操作,包括插入删除和修改,查询的话不支持按顺序查询

    使用起来很简单很方便

     1 #include<cstdio>
     2 #include<ext/rope>
     3 using namespace std;
     4 using namespace __gnu_cxx;
     5 crope list;
     6 int cur;
     7 char ch[3000005];
     8 inline int read()
     9 {
    10     int x=0,f=1;char ch=getchar();
    11     while(ch>'9'||ch<'0') {if(ch=='-')f=-1;ch=getchar();}
    12     while(ch>='0'&&ch<='9') {x=x*10+ch-'0';ch=getchar();}
    13     return x*f;
    14 }
    15 int main()
    16 {
    17     int t,x;
    18     t=read();
    19     char s[10];
    20     while(t--)
    21     {
    22         scanf("%s",s);
    23         switch(s[0])
    24         {
    25             case 'M':cur=read();break;
    26             case 'P':cur--;break;
    27             case 'N':cur++;break;
    28             case 'I':
    29                 x=read();
    30                 for(int i=0;i<x;i++)
    31                 {
    32                     ch[i]=getchar();
    33                     while(ch[i]=='
    ') ch[i]=getchar();
    34                 }
    35                 ch[x]=0;
    36                 list.insert(cur,ch);  //插入串 
    37                 break;
    38             case 'D':
    39                 x=read();
    40                 list.erase(cur,x);  //删除指定长度的串 
    41                 break;
    42             case 'G':
    43                 x=read();
    44                 list.copy(cur,x,ch);  //ch用来展示字符串 
    45                 ch[x]=0;
    46                 puts(ch);
    47         }
    48     }
    49     return 0;
    50 }

    当然还有另外的三个函数,这里附上

        cout<<"test.replace(pos,x);//从pos开始换成x"<<endl;
        text.replace(1,'c');
        cout<<text<<endl;
        text.replace(1,"ccc");
        cout<<text<<endl<<endl<<endl;
     
        cout<<"test.substr(pos,x);//提取pos开始x个"<<endl;
        //text = text.substr(2);这样默认为提取一个
        cout<<text.substr(2)<<endl;
        cout<<text.substr(2,3)<<endl<<endl;
     
        cout<<"test.at(x)/[x];//访问第x个元素"<<endl;
        cout<<text.at(4)<<endl<<endl;
  • 相关阅读:
    AIX6.1 线程模型说明
    多线程专题之线程死锁原因之谜
    多线程执行顺序诡异现象谈,你不知道的pthread_create
    SOA体系结构基础培训教程-规范标准篇
    C# AES要解密的数据的长度无效
    winform命名规范
    winform 打开一个窗体,关闭一个窗体
    VS2017专业版和企业版激活密钥
    AES五种加密模式
    c#POST请求php接口
  • 原文地址:https://www.cnblogs.com/aininot260/p/9512453.html
Copyright © 2011-2022 走看看