Advertisement
Febrin

LIS

Mar 18th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.92 KB | None | 0 0
  1. /* Dejwo to ziomal ®© */
  2.  
  3. #include <bits/stdc++.h>
  4. using namespace std;
  5.  
  6. vector <int> v;
  7.  
  8. int search(vector<int>v, int p, int k, int x)
  9. {
  10.     while(k-p > 1)
  11.     {
  12.         int m = (p+k)/2;
  13.         if(v[m] >= x) k = m;
  14.         else p = m;
  15.     }
  16. return k;
  17. }
  18.  
  19. int LIS()
  20. {
  21.     if(v.size() == 0)return 0;
  22.    
  23.     int dl = 1;
  24.     vector <int> ogon (v.size());
  25.     ogon[0] = v[0];
  26.    
  27.     for(int i=1; i<v.size(); i++)
  28.     {
  29.         if(v[i] < ogon[0]) ogon[0] = v[i];
  30.         else
  31.             if(v[i] > ogon[dl-1]) ogon[dl++] = v[i];
  32.             else
  33.             ogon[search(ogon, -1, dl, v[i])] = v[i];
  34.            
  35.     }
  36.     return dl;
  37. }
  38.  
  39. int main()
  40. {
  41. ios_base::sync_with_stdio(0);
  42.  
  43. int T, N;
  44. cin>>T;
  45.  
  46. for(int j=0; j<T; j++)
  47. {
  48.     cin>>N;
  49.     v.clear();
  50.     for(int i=0; i<N; i++)
  51.     {
  52.         int a; cin>>a;
  53.         v.push_back(a);
  54.     }
  55.     cout<<LIS()<<"\n";
  56. }
  57.  
  58.     return 0;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement