STL rope

Rope函数

类似指针链表的操作,时间复杂度会在n*(n^0.5),可以在很短的时间内实现快速的插入、删除和查找字符串

在g++头文件中,中有成型的块状链表,在using namespace __gnu_cxx;空间中,类似string函数的操作其操作十分方便。

基本操作:

rope T;

T.push_back(x);//在末尾添加x

T.insert(pos,x);//在pos插入x

T.erase(pos,x);//从pos开始删除x个

T.copy(pos,len,x);//从pos开始到pos+len为止用x代替

T.replace(pos,x);//从pos开始换成x

T.substr(pos,x);//提取pos开始x个

T.at(x)/[x];//访问第x个元素

printf("%d\n",T[i])   cout<

rope傻逼题?__?

#include
#include
#include
#include
#include
using namespace std;
using namespace __gnu_cxx;
const int maxn=2e5+7;
const int INF=0x3f3f3f3f;
const double ESP=1e-8;
int a[maxn];
int b[maxn];
int n,m;
int l,r;
int main()
{
    rope p;//rope的下标是从0零0 开始的
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;++i)
        p.push_back(i);
    while(m--)
    {
        scanf("%d%d",&l,&r);
        p.insert(0,p.substr(l-1,r));//先提取一截串,然后把他放到最前面
        p.erase(l-1+r,r);//删除刚刚提取的那一段串,注意添加到前面后的下标和刚刚不一样了
    }
    for(int i=0;i

你可能感兴趣的:(STL,万能的STL)