1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
| #include<algorithm> #include<iostream> #include<iomanip> #include<cstring> #include<cstdlib> #include<vector> #include<cstdio> #include<cmath> #include<queue> using namespace std; inline const int Get_Int() { int num=0,bj=1; char x=getchar(); while(x<'0'||x>'9') { if(x=='-')bj=-1; x=getchar(); } while(x>='0'&&x<='9') { num=num*10+x-'0'; x=getchar(); } return num*bj; } const int maxn=100005,mod=123456789; int n,f[maxn],g[maxn]; struct BIT { int c[maxn],gc[maxn]; #define lowbit(x) x&(-x) void add(int x,int pos) { for(int i=x; i<=100000; i+=lowbit(i)) if(f[pos]>c[i]) { c[i]=f[pos]; gc[i]=g[pos]; } else if(f[pos]==c[i])gc[i]=(gc[i]+g[pos])%mod; } void ask(int x,int pos) { for(int i=x; i>=1; i-=lowbit(i)) { if(f[pos]<c[i]+1) { f[pos]=c[i]+1; g[pos]=gc[i]; } else if(f[pos]==c[i]+1)g[pos]=(g[pos]+gc[i])%mod; } } } bit; int type,a[maxn],Max=0,ans=0; int main() { n=Get_Int(); type=Get_Int(); for(int i=1; i<=n; i++)a[i]=Get_Int(),f[i]=g[i]=1; for(int i=1; i<=n; i++) { bit.ask(a[i]-1,i); bit.add(a[i],i); if(f[i]>Max) { Max=f[i]; ans=g[i]; } else if(f[i]==Max)ans=(ans+g[i])%mod; } printf("%d\n",Max); if(type==1)printf("%d\n",ans); return 0; }
|