AlgoPlus v0.1.0
Loading...
Searching...
No Matches
lis.h
1#ifndef LIS_H
2#define LIS_H
3
4#ifdef __cplusplus
5#include <cstdint>
6#include <iostream>
7#include <vector>
8#endif
9
16template <typename T> int64_t lis(std::vector<T> arr) {
17 std::vector<T> ans;
18 int64_t n = arr.size();
19 for (int64_t i = 0; i < n; i++) {
20 auto it = std::lower_bound(ans.begin(), ans.end(), arr[i]);
21 if (it == ans.end()) {
22 ans.push_back(arr[i]);
23 } else {
24 *it = arr[i];
25 }
26 }
27 return ans.size();
28}
29
30#endif