Advertisement
marco15432

Untitled

Jun 2nd, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define pb push_back
  3. #define fst first
  4. #define snd second
  5. #define fore(i,a,b) for(int i=a,ThxDem=b;i<ThxDem;++i)
  6. #define SZ(x) ((int)x.size())
  7. #define ALL(x) x.begin(),x.end()
  8. #define mset(a,v) memset((a),(v),sizeof(a))
  9. #define FIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
  10. using namespace std;
  11. typedef long long ll;
  12.  
  13. int main()
  14. {
  15. FIN;
  16.  
  17. ll n,m;
  18.  
  19. cin >> n;
  20.  
  21. vector <ll> torres(1,0);
  22.  
  23. fore(i,0,n){
  24. cin >> m;
  25. ll inicio = 0, fin = SZ(torres)-1, medio;
  26.  
  27. if(torres[fin] <= m){torres.push_back(m); continue;}
  28. while(fin - inicio > 1){
  29. medio = (inicio+fin)/2;
  30. if(torres[medio] <= m){
  31. inicio = medio;
  32. }
  33. else if(torres[medio] > m){
  34. fin = medio;
  35. }
  36.  
  37. }
  38. if(torres[inicio] > m){torres[inicio] = m;}
  39. else{torres[fin] = m;}
  40.  
  41. }
  42.  
  43. cout << SZ(torres)-1;
  44.  
  45. return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement