Advertisement
Guest User

Untitled

a guest
Nov 25th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.67 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. const int N = 1e5 + 7;
  6. const int INF = 1e9 + 7;
  7.  
  8. int ar[N];
  9.  
  10. int main()
  11. {
  12.     int n; cin >> n;
  13.     vector<int> f(n + 7, INF);
  14.     f[0] = -INF;
  15.     for(int i = 0 ; i < n ; i ++)
  16.         cin >> ar[i];
  17.  
  18.     for (int i = 0 ; i < n ; i ++)
  19.     {
  20.         int j = (upper_bound(f.begin(), f.end(), ar[i]) - f.begin());
  21.         if (f[j-1] < ar[i] && ar[i] < f[j])
  22.             f[j] = ar[i];
  23.     }
  24.  
  25.     int l = -1, r = -1;
  26.     for(int i = 1 ; i <= n ; i ++)
  27.     {
  28.         if(f[i] != INF && f[i] != -INF)
  29.         {
  30.             r = i;
  31.             if(l == -1)
  32.                 l = i;
  33.         }
  34.     }
  35.     cout << r - l + 1 << endl;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement