Advertisement
vlatkovski

LIS O(N log K)

Jul 9th, 2018
364
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.29 KB | None | 0 0
  1. void LIS(vector<int> &a, vector<int> &L) {
  2.   int n = a.size();
  3.   L.clear();
  4.   vector<int>::iterator it;
  5.   for (int i = 0; i < n; ++i) {
  6.     it = lower_bound(L.begin(), L.end(), a[i]);
  7.     if (it == L.end()) {
  8.       L.push_back(a[i]);
  9.     } else {
  10.       *it = min(*it, a[i]);
  11.     }
  12.   }
  13. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement