#include<bits/stdc++.h> using namespace std; const int maxn=1e6+200; const int INF = 0x3f3f3f3f; int a[maxn],b[maxn],endminv[maxn]; int dp[maxn]; int BinSearch(int l,int r,int key,int typ){ int md; if(typ==0){ while(l<r){ md=(l+r)/2; if(endminv[md]>key){ l=md+1; }else if(endminv[md]<key){ r=md; }else{ return md; } } return l; }else{ while(l<r){ md=(l+r)/2; if(endminv[md]>key){ r=md; }else if(endminv[md]<key){ l=md+1; }else{ return md; } } return l; } } int main(){ int T,n,L,cnt=0; scanf("%d",&T); while(T--){ scanf("%d%d",&n,&L); for(int i=1;i<=n;i++){ scanf("%d",&a[i]); } for(int i=0;i<=n;i++) endminv[i]=-INF; for(int i=n;i>=1;i--){ int x=BinSearch(1,n,a[i],0); endminv[x]=a[i]; dp[i]=x; } memset(endminv,INF,sizeof(endminv)); int ans=0; int len=1; for(int i=L+1;i<=n;i++){ int x=BinSearch(1,n,a[i],1); ans=max(ans,dp[i]+x-1); x=BinSearch(1,n,a[i-L],1); endminv[x]=a[i-L]; len=max(len,x+1); } printf("Case #%d: %d\n",++cnt,max(ans,len-1)); } return 0; } /* 555 5 2 1 4 3 5 7 */
时间: 2024-10-14 04:35:52