uva11922(强行用rope替代spaly)

spaly没学过,用rope水过,

rope是extension库中的东西,codeblocks编译器支持,

需要包含

#include <ext/rope>
using namespace __gnu_cxx;

rope的各种操作时间都是log(n)

 

但是不提供翻转的操作,那么如何实现翻转呢?

只要维护一正一反两个rope,

正rope进行翻转更新的时候用到反rope

反rope进行翻转更新的时候用到正rope

代码非常之短。。。。

 1 #include <iostream>
 2 #include <string.h>
 3 #include <stdio.h>
 4 #include <time.h>
 5 #include <algorithm>
 6 #include <map>
 7 #include <ext/rope>
 8 using namespace __gnu_cxx;
 9 using namespace std;
10 rope<int> ro;
11 rope<int> revro;
12 int main()
13 {
14     int n,m;
15     scanf("%d%d",&n,&m);
16     for(int i=1;i<=n;++i)
17     {
18         ro.append(i);
19 
20     }
21     for(int i=n;i>=1;--i)
22     {
23         revro.append(i);
24     }
25     int l,r;
26     while(m--)
27     {
28         scanf("%d%d",&l,&r);
29         l--,r--;
30         rope<int> tmp = ro.substr(l,r-l+1);
31         rope<int> revtmp = revro.substr(n-r-1,r-l+1);
32         ro.erase(l,r-l+1);
33         revro.erase(n-r-1,r-l+1);
34         ro.append(revtmp);
35         revro = tmp + revro;
36     }
37     for(int i=0;i<n;++i)
38         printf("%d\n",ro[i]);
39 
40 }

 

posted @ 2015-10-11 19:01  justPassBy  阅读(268)  评论(0编辑  收藏  举报