zoukankan      html  css  js  c++  java
  • 【SRM-07 D】天才麻将少女KPM

    Description

    天才麻将少女KPM立志要在日麻界闯出一番名堂。
    KPM上周叒打了n场麻将,但她这次又没控分,而且因为是全市参与的麻将大赛,所以她的名次范围是0..10^5。
    名次可能等于0是因为KPM那场没去打= =
    没去打就意味着无限的可能性。
    KPM叒想要让自己的名次严格递增。为了避免被妹子怀疑,她只能把没打的比赛的名次改成T..R中的整数
    当然,n场全部严格递增是很难做到的。你只需要求出可能的最长递增子序列长度就好了。

    Input

    第一行三个整数n,T,R。
    第二行n个整数,表示n场的排名。

    Output

    可能的最长递增子序列长度。

    Sample Input

    5 1 4 3 0 5 9 2

    Sample Output

    4

    HINT

    对于100%的数据: 1leq nleq 10^5,1leq Tleq Rleq 10^5

     

    %%%来自yy的题解

    自己的代码没有写差分,又丑又慢QAQ

      1 #include<cstdio>
      2 #include<algorithm>
      3 #include<cstring>
      4 #include<cstdlib>
      5 #include<iostream>
      6 #define LL long long
      7 using namespace std;
      8 const int N=2e5+5;
      9 int n,L,R,a,tmp,cnt=1e5;
     10 int root,rt1,rt2,rt3,st[N],ch[N][9];
     11 #define lc ch][0
     12 #define rc ch][1
     13 #define rnd ch][2
     14 #define sz ch][3
     15 #define v ch][4
     16 #define tag ch][5
     17 #define mx ch][6
     18 #define mn ch][7
     19 #define cov ch][8
     20 int read()
     21 {
     22     int x=0,f=1;char c=getchar();
     23     while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
     24     while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
     25     return x*f;
     26 }
     27 void up(int w)
     28 {
     29     w[sz]=w[lc][sz]+w[rc][sz]+1;w[mx]=w[mn]=w[v];
     30     if(w[lc])w[mx]=max(w[mx],w[lc][mx]),w[mn]=min(w[mn],w[lc][mn]);
     31     if(w[rc])w[mx]=max(w[mx],w[rc][mx]),w[mn]=min(w[mn],w[rc][mn]);
     32 }
     33 void dn(int w)
     34 {
     35     if(w[cov])
     36     {
     37         w[lc][v]=w[lc][cov]=w[lc][mx]=w[lc][mn]=w[cov];
     38         w[rc][v]=w[rc][cov]=w[rc][mx]=w[rc][mn]=w[cov];
     39         w[lc][tag]=w[rc][tag]=0;
     40         w[cov]=0;
     41     }
     42     if(w[tag])
     43     {
     44         w[lc][v]+=w[tag];w[lc][tag]+=w[tag];
     45         w[lc][mx]+=w[tag];w[lc][mn]+=w[tag];
     46         w[rc][v]+=w[tag];w[rc][tag]+=w[tag];
     47         w[rc][mx]+=w[tag];w[rc][mn]+=w[tag];
     48         w[tag]=0;
     49     }
     50 }
     51 void dfs(int w){if(!w)return;dfs(w[lc]);dfs(w[rc]);up(w);}
     52 int build()
     53 {
     54     int top=0;
     55     for(int w=1;w<=1e5;w++)
     56     {
     57         w[rnd]=rand();
     58         while(top&&st[top][rnd]>w[rnd])
     59         {
     60             st[top][rc]=w[lc];
     61             w[lc]=st[top--];
     62         }
     63         st[top][rc]=w;st[++top]=w;
     64     }
     65     ch[0][1]=0;dfs(st[1]);
     66     return st[1];
     67 }
     68 void split(int w,int& l,int& r,int k)
     69 {
     70     if(!w){l=r=0;return;}
     71     dn(w);int lson=w[lc][sz];
     72     if(k<=lson){r=w;split(w[lc],l,w[lc],k);}
     73     else{l=w;split(w[rc],w[rc],r,k-lson-1);}
     74     up(w);
     75 }
     76 int merge(int a,int b)
     77 {
     78     if(!a||!b)return a+b;
     79     if(a[rnd]<b[rnd]){dn(a);a[rc]=merge(a[rc],b);up(a);return a;}
     80     else{dn(b);b[lc]=merge(a,b[lc]);up(b);return b;}
     81 }
     82 int rank(int w,int k)
     83 {
     84     if(!w)return 0;dn(w);
     85     int lson=w[lc][sz];
     86     if(k==lson+1)return w[v];
     87     if(k<=lson)return rank(w[lc],k);
     88     else return rank(w[rc],k-lson-1);
     89 }
     90 void ins(int& w,int x,int k)
     91 {
     92     dn(w);
     93     if(x[rnd]<w[rnd]||!w){split(w,x[lc],x[rc],k);w=x;up(w);return;}
     94     int lson=w[lc][sz];
     95     if(k<=lson)ins(w[lc],x,k);
     96     else ins(w[rc],x,k-lson-1);
     97     up(w);
     98 }
     99 void del(int& w,int k)
    100 {
    101     dn(w);
    102     int lson=w[lc][sz];
    103     if(k==lson+1){w=merge(w[lc],w[rc]);return;}
    104     if(k<=lson)del(w[lc],k);
    105     else del(w[rc],k-lson-1);
    106     up(w);
    107 }
    108 void add(int L,int R,int V)
    109 {
    110     rt1=rt2=rt3=0;split(root,rt2,rt3,R);
    111     root=rt2;rt2=0;split(root,rt1,rt2,L-1);
    112     rt2[tag]+=V;rt2[v]+=V;rt2[mx]+=V;rt2[mn]+=V;
    113     root=merge(rt1,rt2);root=merge(root,rt3);
    114 }
    115 void cover(int w,int V)
    116 {
    117     if(!w||w[mn]>=V)return;
    118     dn(w);if(w[v]<V)w[v]=V;
    119     if(w[mx]<=V){w[cov]=V;w[tag]=0;up(w);return;}
    120     cover(w[lc],V);cover(w[rc],V);
    121     up(w);
    122 }
    123 void update(int L,int R,int V)
    124 {
    125     rt1=rt2=rt3=0;split(root,rt2,rt3,R);
    126     root=rt2;rt2=0;split(root,rt1,rt2,L-1);
    127     cover(rt2,V);
    128     root=merge(rt1,rt2);root=merge(root,rt3);
    129 }
    130 int main()
    131 {
    132     n=read();L=read();R=read();root=build();
    133     for(int i=1;i<=n;i++)
    134     {
    135         a=read();
    136         if(a>0)
    137         {
    138             tmp=rank(root,a-1)+1;
    139             update(a,1e5,tmp);
    140         }
    141         else
    142         {
    143             del(root,R);cnt++;
    144             tmp=rank(root,L-1);
    145             cnt[v]=tmp;cnt[rnd]=rand();
    146             ins(root,cnt,L-1);
    147             add(L,R,1);tmp=rank(root,R);
    148             if(R!=1e5)update(R+1,1e5,tmp);
    149         }
    150     }
    151     printf("%d",root[mx]);
    152     return 0;
    153 }
    View Code

                                                                                                                                                                                                                                                                       

  • 相关阅读:
    spark on yarn模式下内存资源管理(笔记1)
    面试题10.3-变态跳台阶
    面试题10.2-青蛙跳
    面试题9-斐波那契数列
    面试题9-用两个栈来实现一个队列,完成队列的Push和Pop操作
    面试题6:输入一个链表,按链表值从尾到头的顺序返回一个ArrayList
    鸢尾花数据集-iris.data
    class之cls
    python 装饰器
    supervisor python开发的进程管理工具
  • 原文地址:https://www.cnblogs.com/zsnuo/p/8087435.html
Copyright © 2011-2022 走看看