This documentation is automatically generated by online-judge-tools/verification-helper
View the Project on GitHub ningenMe/compro-library
#define PROBLEM "http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DPL_1_D" #include <vector> #include <iostream> #include <algorithm> using namespace std; #include "../../lib/00-util/FastIO.cpp" #include "../../lib/13-static-range-query/LongestIncreasingSubsequence.cpp" int main(void){ cin.tie(0);ios::sync_with_stdio(false); int N; read(N); vector<long long> a(N); for(int i=0;i<N;++i) read(a[i]); LongestIncreasingSubsequence lis(a); cout << lis.size() << endl; return 0; }
#line 1 "test/static-range-query/LongestIncreasingSubsequence-size.test.cpp" #define PROBLEM "http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DPL_1_D" #include <vector> #include <iostream> #include <algorithm> using namespace std; #line 1 "lib/00-util/FastIO.cpp" /* * @title FastIO * @docs md/util/FastIO.md */ class FastIO{ private: inline static constexpr int ch_0='0'; inline static constexpr int ch_9='9'; inline static constexpr int ch_n='-'; inline static constexpr int ch_s=' '; inline static constexpr int ch_l='\n'; inline static void endline_skip(char& ch) { while(ch==ch_l) ch=getchar(); } template<typename T> inline static void read_integer(T &x) { int neg=0; char ch; x=0; ch=getchar(); endline_skip(ch); if(ch==ch_n) neg=1,ch=getchar(); for(;(ch_0 <= ch && ch <= ch_9); ch = getchar()) x = x*10 + (ch-ch_0); if(neg) x*=-1; } template<typename T> inline static void read_unsigned_integer(T &x) { char ch; x=0; ch=getchar(); endline_skip(ch); for(;(ch_0 <= ch && ch <= ch_9); ch = getchar()) x = x*10 + (ch-ch_0); } inline static void read_string(string &x) { char ch; x=""; ch=getchar(); endline_skip(ch); for(;(ch != ch_s && ch!=ch_l); ch = getchar()) x.push_back(ch); } inline static char ar[40]; inline static char *ch_ar; template<typename T> inline static void write_integer(T x) { ch_ar=ar; if(x< 0) putchar(ch_n), x=-x; if(x==0) putchar(ch_0); for(;x;x/=10) *ch_ar++=(ch_0+x%10); while(ch_ar--!=ar) putchar(*ch_ar); } public: inline static void read(int &x) {read_integer<int>(x);} inline static void read(long long &x) {read_integer<long long>(x);} inline static void read(unsigned int &x) {read_unsigned_integer<unsigned int>(x);} inline static void read(unsigned long long &x) {read_unsigned_integer<unsigned long long>(x);} inline static void read(string &x) {read_string(x);} inline static void read(__int128_t &x) {read_integer<__int128_t>(x);} inline static void write(__int128_t x) {write_integer<__int128_t>(x);} inline static void write(char x) {putchar(x);} }; #define read(arg) FastIO::read(arg) #define write(arg) FastIO::write(arg) #line 1 "lib/13-static-range-query/LongestIncreasingSubsequence.cpp" /* * @title LongestIncreasingSubsequence - LIS * @docs md/13-static-range-query/LongestIncreasingSubsequence.md */ template<class T> class LongestIncreasingSubsequence { size_t length; size_t sz; vector<size_t> dp_key; vector<T> dp_val; vector<size_t> pre; public: LongestIncreasingSubsequence(const vector<T> & ar, T inf=3e18) { length = ar.size(); dp_key.resize(length, length); dp_val.resize(length, inf); pre.resize(length); for (int i = 0; i < length; ++i) { int key = lower_bound(dp_val.begin(), dp_val.end(), ar[i]) - dp_val.begin(); dp_val[key] = ar[i]; dp_key[key] = i; pre[i] = (key ? dp_key[key-1] : length); }; sz = lower_bound(dp_val.begin(), dp_val.end(), inf) - dp_val.begin(); } int size() { return sz; } vector<int> index() { vector<int> res; for(size_t idx = dp_key[sz-1]; idx != length; idx = pre[idx]) { res.push_back(idx); } reverse(res.begin(), res.end()); return res; } }; #line 9 "test/static-range-query/LongestIncreasingSubsequence-size.test.cpp" int main(void){ cin.tie(0);ios::sync_with_stdio(false); int N; read(N); vector<long long> a(N); for(int i=0;i<N;++i) read(a[i]); LongestIncreasingSubsequence lis(a); cout << lis.size() << endl; return 0; }