HDU 1890 Splay区间翻转(二)

2015-01-27 05:59:27 · 作者: · 浏览: 9
部分已经有序啦,不删除会对后面的操作有影响)。翻转最好一次翻转两层,开始我只翻转一层就超时了。

代码:

/*************************************************************************
    > File Name: Spaly.cpp
    > Author: acvcla
    > QQ:
    > Mail: acvcla@gmail.com
    > Created Time: 2014?ê11??16?? ?????? 00?±14·?26??
 ************************************************************************/
#include
  
   
#include
   
     #include
    
      #include
     
       #include
      
        #include
        #include
        
          #include
         
           #include
          
            #include
           
             #include
            
              #include
             
               #include
              
                using namespace std; typedef long long LL; const int maxn = 1e5 + 100; #define rep(i,a,b) for(int i=(a);i<=(b);i++) #define pb push_back int ch[maxn][2],pre[maxn],siz[maxn],rev[maxn]; int root,tot; struct node { int first,second; bool operator < (const node &a)const{ if(first==a.first)return second
               
                R)return; int mid=(R+L)>>1; newnode(x,fa,mid); built(ch[x][0],L,mid-1,x); built(ch[x][1],mid+1,R,x); push_up(x); } inline void init(int n) { pre[0]=siz[0]=0; root=tot=ch[0][0]=ch[0][1]=0; for(int i=1;i<=n;i++){ scanf("%d",&A[i].first); A[i].second=i; } sort(A+1,A+1+n); built(root,1,n,0); } int main(int argc, char const *argv[]) { int n; while(~scanf("%d",&n)&&n){ init(n); rep(i,1,n-1){ Splay(A[i].second,0); update_rev(ch[root][0]); printf("%d ",i+siz[ch[root][0]]); remove_root(); } printf("%d\n",n); } return 0; }