Advertisement
mickypinata

PROG-T1151: Tree

Jul 3rd, 2021
1,117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.70 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. const int N = 2e5;
  5.  
  6. int lis[N + 1];
  7.  
  8. int main(){
  9.  
  10.     int nTree;
  11.     scanf("%d", &nTree);
  12.     int mxLen = 0;
  13.     for(int i = 1; i <= nTree; ++i){
  14.         int x;
  15.         scanf("%d", &x);
  16.         lis[mxLen + 1] = 1e9;
  17.         int l = 1;
  18.         int r = mxLen + 1;
  19.         int ans = mxLen + 1;
  20.         while(l <= r){
  21.             int m = (l + r) / 2;
  22.             if(lis[m] >= x){
  23.                 ans = min(ans, m);
  24.                 r = m - 1;
  25.             } else {
  26.                 l = m + 1;
  27.             }
  28.         }
  29.         lis[ans] = x;
  30.         if(ans == mxLen + 1){
  31.             ++mxLen;
  32.         }
  33.     }
  34.     cout << mxLen;
  35.  
  36.     return 0;
  37. }
  38.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement