This documentation is automatically generated by online-judge-tools/verification-helper
最長増加部分列の長さを求める
関数
lis($n, A, f$)
${\rm O}(n \log n)$
/*
* @title longest-increasing-subsequence(dp)
* @docs kyopro/docs/LIS_dp.md
*/
//st が true の時、狭義単調増加
int lis(const int& n, const vector<int>& a, const bool& st) {
vector<int> dp(n);
fill(all(dp), INF);
vector<int>::iterator ite;
rep(i, n) {
if (st)ite = lower_bound(all(dp), a[i]);
else ite = upper_bound(all(dp), a[i]);
if (ite != dp.end())*ite = a[i];
}
return distance(dp.begin(), lower_bound(all(dp), INF));
}
#line 1 "kyopro/library/algorithm/LIS_dp.cpp"
/*
* @title longest-increasing-subsequence(dp)
* @docs kyopro/docs/LIS_dp.md
*/
//st が true の時、狭義単調増加
int lis(const int& n, const vector<int>& a, const bool& st) {
vector<int> dp(n);
fill(all(dp), INF);
vector<int>::iterator ite;
rep(i, n) {
if (st)ite = lower_bound(all(dp), a[i]);
else ite = upper_bound(all(dp), a[i]);
if (ite != dp.end())*ite = a[i];
}
return distance(dp.begin(), lower_bound(all(dp), INF));
}