可持化永久树 的 STL ( rope )

 

rope 的基本操作

#include <ext/rope>
using namespace __gnu_cxx;
int a[1000];
rope<int> x;
rope<int> x(a,a + n);
rope<int> a(x);
 
x->at(10);
x[10];
x->push_back(x)     // 在末尾添加x
x->insert(pos,x)    // 在pos插入x
x->erase(pos,x)     // 从pos开始删除x个
x->replace(pos,x)   // 从pos开始换成x
x->substr(pos,x)    // 提取pos开始x个

牛客 E。Shuffle Cards

#include<iostream>
#include<ext/rope>
using namespace std;
using namespace __gnu_cxx;
rope<int>a;
int main(){
    int n,m,x,y;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++) a.push_back(i);
    for(int i=0;i<m;i++){
        scanf("%d%d",&x,&y);
        a.insert(0,a.substr(x-1,y));
        a.erase(x+y-1,y);
    }
    printf("%d",a[0]);
    for(int i=1;i<n;i++) printf(" %d",a[i]);
    puts("");
}

 

 

posted @ 2018-07-27 16:11  shuai_hui  阅读(338)  评论(0编辑  收藏  举报