splay竟然还有库函数。。。
真好~
问题:给一个 N N 表示 个数 1到N 1 到 N ,给一个 K K 表示 次操作,然后 L L ,表示从 L开始 L 开 始 长度为 len l e n 这么多个数移动到最前面,问 K K 次操作后,数列什么样子?
的时候这个库函数的时间是 800 800 多 ms m s ,但是同学手写的板子能跑到 200 200 多 ms 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");
}