最长上升子序列 nlogn

时间:2024-06-18 00:06:25
const LL N = ;
LL num[N];
LL dp[N];
LL go(LL l, LL r, LL k)
{
for (; r >= l; r--)
if (dp[r] <= k)
return r;
return l;
}
LL bins(LL l, LL r, LL k)
{
while (r - l >= )
{
if (r - l <= )
return go(l, r, k);
LL mid = (l + r) >> ;
if (dp[mid] > k)
r = mid;
else
l = mid;
}
}
LL solve(LL n)
{
fill(dp, dp + N, N + );
dp[] = ;
LL ans = ;
for (int i = ; i < n; i++)
{
LL e = num[i];
LL ads = bins(, i, e);
dp[ads + ] = min(dp[ads + ], e);
ans = max(ans, ads+);
}
//cout << ans << endl;
return ans;
}