正文
增加 6 行删除 6 行
78 行未改动79808182838485868724 行未改动11211311411511611711811912012112212312412512612712812913013178 行未改动}```2. 二分+贪心,创建一个b数组,存储所有最优 LIS的可能值,之后LIS板子,在所有解中找到答案(用二分的)。```cpp#include<bits/stdc++.h>using namespace std;const int N=5e5+10;long long idx=0,n,a[N],b[N],b_len=1,res[N],dp[N];vector<long long> e[N];24 行未改动}}dfs(1,0);b[b_len]=a[1];long long max_ans=1;for(int i=2;i<=n;i++){if(b[b_len]<a[i]){dp[i]=b_len+1;b[++b_len]=a[i];}else{int x=lower_bound(b+1,b+b_len+1,a[i])-(b+1);dp[i]=x+1;b[x+1]=a[i];}max_ans=max(max_ans,dp[i]);}cout<<max_ans;return 0;}```78 行未改动79808182838485868724 行未改动11211311411511611711811912012112212312412512612712812913013178 行未改动}```2. 二分+贪心,创建一个b数组,存储所有最优 LIS的可能值,之后LIS板子,在所有解中找到答案(用二分的)。```cpp#include<bits/stdc++.h>using namespace std;const int N=5e5+10;long long idx=0,n,a[N],b[N],b_len=1,res[N],dp[N];vector<long long> e[N];24 行未改动}}dfs(1,0);b[b_len]=a[1];long long max_ans=1;for(int i=2;i<=n;i++){if(b[b_len]<a[i]){dp[i]=b_len+1;b[++b_len]=a[i];}else{int x=lower_bound(b+1,b+b_len+1,a[i])-(b+1);dp[i]=x+1;b[x+1]=a[i];}max_ans=max(max_ans,dp[i]);}cout<<max_ans;return 0;}```