splay库函数

splay竟然还有库函数。。。
真好~

问题:给一个 N 表示 N 个数 1 N ,给一个 K 表示 K 次操作,然后 L l e n 表示从 L 长度为 l e n 这么多个数移动到最前面,问 K 次操作后,数列什么样子?

N = 1 e 5 K <= 1 e 5 的时候这个库函数的时间是 800 m s ,但是同学手写的板子能跑到 200 m s

#include"bits/stdc++.h"
#include"ext/rope"
#define out(x) cout<<#x<<"="<<x
using namespace __gnu_cxx;
using namespace std;
typedef long long LL;
const int maxn=1e6+5;
rope<int>ro;
int main()
{
    int N,K;
    cin>>N>>K;
    for(int i=1;i<=N;i++)ro.append(i);
    while(K--)
    {
        int L,len;
        cin>>L>>len;
        L--;
        rope<int>tmp;
        tmp=ro.substr(L,len);
        ro.erase(L,len);
        ro.insert(0,tmp);
    }
    for(int i=0;i<N;i++)printf("%d ",ro[i]);
    printf("\n");
}

猜你喜欢

转载自blog.csdn.net/SwustLpf/article/details/81220599