Alex_tz307

Longest Strictly Increasing Subsequence

Sep 19th, 2020 (edited)
115
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.  
  3. using namespace std;
  4.  
  5. int main() {
  6.     ios_base::sync_with_stdio(false);
  7.     cin.tie(nullptr);
  8.     cout.tie(nullptr);
  9.     int T;
  10.     cin >> T;
  11.     while(T--) {
  12.         int N;
  13.         cin >> N;
  14.         vector < int > a(N), deck;
  15.         for(int& x : a)
  16.             cin >> x;
  17.         for(int x : a) {
  18.             if(deck.empty()) {
  19.                 deck.emplace_back(x);
  20.                 continue;
  21.             }
  22.             if(x > deck.back()) {
  23.                 deck.emplace_back(x);
  24.                 continue;
  25.             }
  26.             auto it = lower_bound(deck.begin(), deck.end(), x);
  27.             *it = x;
  28.         }
  29.         cout << deck.size() << '\n';
  30.     }
  31. }
Add Comment
Please, Sign In to add comment