Advertisement
Guest User

Untitled

a guest
Feb 15th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.73 KB | None | 0 0
  1.         if(a[m] < val)
  2.             ini = m;
  3.         else
  4.             fin = m, pos = min(pos, m);
  5.     }
  6.  
  7.     if(a[ini] >= val)
  8.         pos = min(pos, ini);
  9.     if(a[fin] >= val)
  10.         pos = min(pos, fin);
  11.  
  12.     return pos;
  13. }
  14.  
  15. ll longestIncreasingSubsequence()
  16. {
  17.     LIS = 0, a[0] = v[0];
  18.  
  19.     for1(i, (n - 1))
  20.     {
  21.         if(v[i] < a[0])
  22.             a[0] = v[i];
  23.         else if(v[i] > a[LIS])
  24.             LIS++, a[LIS] = v[i];
  25.         else
  26.             a[ceilBinario(v[i])] = v[i];
  27.     }
  28.  
  29.     return (LIS + 1);
  30. }
  31.  
  32. int main()
  33. {
  34.     ios::sync_with_stdio(false);
  35.     cin.tie(NULL);
  36.  
  37.     cin >> n;
  38.  
  39.     forn(i, n)
  40.         cin >> v[i];
  41.  
  42.     cout << longestIncreasingSubsequence() << "\n";
  43.  
  44.     return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement