Removed Interval
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1703 Accepted Submission(s): 558
, a subsequence b1,b2,…,bk
of A
is referred as increasing if b1<b2<…<bk
. LY has just learned how to find the longest increasing subsequence (LIS).
Now that he has to select L
consecutive numbers and remove them from A
for some mysterious reasons. He can choose arbitrary starting position of the selected interval so that the length of the LIS of the remaining numbers is maximized. Can you help him with this problem?
indicating the number of test cases (T≤100
).
For each test case, the first line consists of two numbers N
and L
as described above (1≤N≤100000,0≤L≤N
). The second line consists of N
integers indicating the sequence. The absolute value of the numbers is no greater than 109
.
The sum of N over all test cases will not exceed 500000.
is the test case number starting from 1. Y
is the maximum length of LIS after removing the interval.
5 2
1 2 3 4 5
5 3
5 4 3 2 1
Case #2: 1
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<map>
#include<queue>
#include<stack>
#include<vector>
#include<bitset>
#include<set>
#define ll __int64
#define mod 100000000
#define N 5e6+10
#define M 1e
using namespace std;
int t;
int n,l;
int a[],b[];
int dp[];
int ans[];
int main()
{
scanf("%d",&t);
for(int i=;i<=t;i++)
{
scanf("%d %d",&n,&l);
a[]=;
for(int j=;j<=n;j++){
scanf("%d",&a[j]);
b[j]=-a[j];
}
int exm=;
ans[exm]=a[];
dp[]=;
for(int j=;j<=n;j++)
{
if(a[j]>ans[exm]){
exm++;
ans[exm]=a[j];
dp[j]=exm;
}
else
{
int pos=lower_bound(ans+,ans+exm,a[j])-ans;
ans[pos]=a[j];
dp[j]=pos;
}
}
int an=;
for(int j=;j<=n;j++)
ans[j]=1e9;
int re=;
for(int j=n-l;j>=;j--)
{
int x=lower_bound(ans,ans+n,b[j])-ans;//
an=max(an,dp[j]+x);
int y=lower_bound(ans,ans+n,b[j+l])-ans;
ans[y]=b[j+l];
re=max(re,y+);
}
printf("Case #%d: %d\n",i,max(an,re));
}
return ;
}
/*
6
6 2
1 3 5 7 2 4
*/