zoukankan      html  css  js  c++  java
  • bzoj 3173

    后面插进取的数并不影响前面的结果,所以用splay把最后的序列求出来直接LIS即可

     1 #include<bits/stdc++.h>
     2 #define inc(i,l,r) for(int i=l;i<=r;i++)
     3 #define dec(i,l,r) for(int i=l;i>=r;i--)
     4 #define link(x) for(edge *j=h[x];j;j=j->next)
     5 #define mem(a) memset(a,0,sizeof(a))
     6 #define inf 1e9
     7 #define ll long long
     8 #define succ(x) (1<<x)
     9 #define NM 100000+5
    10 using namespace std;
    11 int read(){
    12     int x=0,f=1;char ch=getchar();
    13     while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
    14     while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
    15     return x*f;
    16 }
    17 int n,_x,_t,a[NM],b[NM],c[NM][2],f[NM],tot,root,d[NM],len;
    18 int _d(int x){
    19     return c[f[x]][1]==x;
    20 }
    21 void newnode(int &r,int fa,int k){
    22     r=++tot;f[r]=fa;c[r][0]=c[r][1]=0;b[r]=1;
    23 }
    24 void rot(int x){
    25     int y=f[x],kind=!_d(x);
    26     c[y][!kind]=c[x][kind];f[c[x][kind]]=y;
    27     c[f[y]][_d(y)]=x;f[x]=f[y];
    28     c[x][kind]=y;f[y]=x;
    29     b[y]=b[c[y][0]]+b[c[y][1]]+1;b[x]=b[c[x][0]]+b[c[x][1]]+1;
    30 }
    31 void splay(int x,int goal=0){
    32     for(int y=f[x];y!=goal;y=f[x]){
    33         if(f[y]!=goal)
    34         _d(x)==_d(y)?rot(y):rot(x);
    35         rot(x);
    36     }
    37     if(goal==0)root=x;
    38 }
    39 void ins(int x){
    40     int r=root;
    41     if(x!=tot+1){
    42     while(1)
    43     if(b[c[r][0]]>=x)r=c[r][0];
    44         else{
    45         x-=b[c[r][0]]+1;
    46         if(!x)break;
    47         r=c[r][1];
    48     }
    49     if(!c[r][0]){
    50         newnode(c[r][0],r,_t);splay(c[r][0]);return;
    51     }
    52     for(r=c[r][0];c[r][1];)r=c[r][1];
    53     }else
    54     while(c[r][1])r=c[r][1];
    55     newnode(c[r][1],r,_t);
    56     splay(c[r][1]);
    57 }
    58 void out(int r){
    59     if(c[r][0])out(c[r][0]);
    60     a[++n]=r;
    61     if(c[r][1])out(c[r][1]);
    62 }
    63 int main(){
    64 //    freopen("data.in","r",stdin);
    65     n=read()-1;
    66     read();newnode(root,0,_t=1);
    67     while(n--){
    68         ++_t;_x=read()+1;
    69         ins(_x);
    70     }
    71     n++;
    72     out(root);
    73 //    inc(i,1,n)printf("%d ",a[i]);
    74 //    printf("
    ");
    75     d[len=1]=a[1];
    76     inc(i,2,n)
    77     if(d[len]>=a[i])d[lower_bound(d,d+len+1,a[i])-d]=a[i];
    78     else d[++len]=a[i];
    79     mem(b);_t=0;
    80     inc(i,1,len)b[d[i]]=i;
    81     inc(i,1,n){
    82         _t=max(b[i],_t);
    83         printf("%d
    ",_t);
    84     }
    85     return 0;
    86 }
    View Code
  • 相关阅读:
    20145215《信息安全系统设计基础》第三周学习总结
    20145215《信息安全系统设计基础》第二周学习总结
    Ubuntu下git的安装与使用
    20145215《信息安全系统设计基础》第一周学习总结
    20145215《信息安全系统设计基础》第0周学习总结
    第一周Web类WriteUp
    20145215《Java程序设计》课程总结
    20145215《Java程序设计》第10周学习总结
    python字符串基本方法
    python数据类型
  • 原文地址:https://www.cnblogs.com/onlyRP/p/5111254.html
Copyright © 2011-2022 走看看