【BZOJ3678】Wangxz和OJ

题意:

不想讲

题解:

Rope真香!

正解是Splay缩点,访问时再拆成一个序列

代码:

 1 //STL dafa good!
 2 #include<algorithm>
 3 #include<iostream>
 4 #include<cstring>
 5 #include<cstdio>
 6 #include<cmath>
 7 #include<queue>
 8 #include<ext/rope>
 9 #define inf 2147483647
10 #define eps 1e-9
11 using namespace std;
12 using namespace __gnu_cxx;
13 typedef long long ll;
14 rope<short>rp;
15 short a[20001],s[200001];
16 int l,r,p,tmp,n,m,op;
17 int main(){
18     scanf("%d%d",&n,&m);
19     for(int i=0;i<n;i++)scanf("%d",&a[i]);
20     rp=rope<short>(a,a+n);
21     for(int i=1;i<=m;i++){
22         scanf("%d",&op);
23         if(op==0){
24             scanf("%d%d%d",&p,&l,&r);
25             tmp=0;
26             for(int i=l;i<=r;i++)s[tmp++]=i;
27             rp=rp.substr(0,p)+rope<short>(s,s+r-l+1)+rp.substr(p,rp.size()-p);
28         }
29         if(op==1){
30             scanf("%d%d",&l,&r);
31             rp=rp.substr(0,l-1)+rp.substr(r,rp.size()-r);
32         }
33         if(op==2){
34             scanf("%d",&p);
35             printf("%d\n",rp[p-1]);
36         }
37     }
38     return 0;
39 }
40 //zhenshanren
posted @ 2018-09-11 20:34  DCDCBigBig  阅读(206)  评论(0编辑  收藏  举报