Language: C++

#include <algorithm>
#include <iostream>
#include <list>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }

// vector
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i]; if (i < len - 1) s << "\t";
  }
  return s;
}

// index が条件を満たすかどうか
bool isOK(vector<int> & a, int index, int key) {
    if (a[index] < key) return true;
    else return false;
}

// 汎用的な二分探索のテンプレ
int binary_search(vector<int> & a, int key) {
    int ok = (int)a.size(); // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()
    int ng = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1

    /* ok と ng のどちらが大きいかわからないことを考慮 */
    while (abs(ok - ng) > 1) {
        int mid = (ok + ng) / 2;

        if (isOK(a, mid, key)) ok = mid;
        else ng = mid;
    }
    return ok;
}

int main() {
  int n;
  cin >> n;
  vector<int> la(n);
  for (int i = 0; i < n; ++i) {
    cin >> la[i];
  }
  vector<int> lc;
  lc.push_back(la[0]);
  for (int i = 1; i < la.size(); ++i) {
    int key = la[i];
    int ret = binary_search(lc, key);
    if (ret == lc.size()) {
      lc.push_back(key);
    }
    else {
      lc[ret] = key;
    }
  }
  cout << lc.size() << endl;
}


Compiler output:
a.cc:14:60: error: 'vector' does not name a type
   14 | template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
      |                                                            ^~~~~~
a.cc:14:66: error: expected ',' or '...' before '<' token
   14 | template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
      |                                                                  ^
a.cc: In function 'std::ostream& operator<<(std::ostream&, int)':
a.cc:15:13: error: 'v' was not declared in this scope
   15 |   int len = v.size();
      |             ^
a.cc: At global scope:
a.cc:23:11: error: 'vector' was not declared in this scope
   23 | bool isOK(vector<int> & a, int index, int key) {
      |           ^~~~~~
a.cc:4:1: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
    3 | #include <list>
  +++ |+#include <vector>
    4 | using namespace std;
a.cc:23:18: error: expected primary-expression before 'int'
   23 | bool isOK(vector<int> & a, int index, int key) {
      |                  ^~~
a.cc:23:28: error: expected primary-expression before 'int'
   23 | bool isOK(vector<int> & a, int index, int key) {
      |                            ^~~
a.cc:23:39: error: expected primary-expression before 'int'
   23 | bool isOK(vector<int> & a, int index, int key) {
      |                                       ^~~
a.cc:23:46: error: expression list treated as compound expression in initializer [-fpermissive]
   23 | bool isOK(vector<int> & a, int index, int key) {
      |                                              ^
a.cc:29:19: error: 'vector' was not declared in this scope
   29 | int binary_search(vector<int> & a, int key) {
      |                   ^~~~~~
a.cc:29:19: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
a.cc:29:26: error: expected primary-expression before 'int'
   29 | int binary_search(vector<int> & a, int key) {
      |                          ^~~
a.cc:29:36: error: expected primary-expression before 'int'
   29 | int binary_search(vector<int> & a, int key) {
      |                                    ^~~
a.cc:29:43: error: expression list treated as compound expression in initializer [-fpermissive]
   29 | int binary_search(vector<int> & a, int key) {
      |                                           ^
a.cc: In function 'int main()':
a.cc:46:3: error: 'vector' was not declared in this scope
   46 |   vector<int> la(n);
      |   ^~~~~~
a.cc:46:3: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
a.cc:46:10: error: expected primary-expression before 'int'
   46 |   vector<int> la(n);
      |          ^~~
a.cc:48:12: error: 'la' was not declared in this scope; did you mean 'll'?
   48 |     cin >> la[i];
      |            ^~
      |            ll
a.cc:50:10: error: expected primary-expression before 'int'
   50 |   vector<int> lc;
      |          ^~~
a.cc:51:3: error: 'lc' was not declared in this scope; did you mean 'll'?
   51 |   lc.push_back(la[0]);
      |   ^~
      |   ll
a.cc:51:16: error: 'la' was not declared in this scope; did you mean 'll'?
   51 |   lc.push_back(la[0]);
      |                ^~
      |                ll
a.cc:54:15: error: reference to 'binary_search' is ambiguous
   54 |     int ret = binary_search(lc, key);
      |               ^~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:61,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algo.h:2228:5: note: candidates are: 'template<class _FIter, class _Tp, class _Compare> bool std::binary_search(_FIter, _FIter, const _Tp&, _Compare)'
 2228 |     binary_search(_ForwardIterator __first, _ForwardIterator __last,
      |     ^~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:2194:5: note:                 'template<class _FIter, class _Tp> bool std::binary_search(_FIter, _FIter, const _Tp&)'
 2194 |     binary_search(_ForwardIterator __first, _ForwardIterator __last,
      |     ^~~~~~~~~~~~~
a.cc:29:5: note:                 'int binary_search'
   29 | int binary_search(vector<int> & a, int key) {
      |     ^~~~~~~~~~~~~