1 // accepted 3540 kb 62 MS 2 // DP longest ascending subsequence 3 # include <cstdio> 4 # include <cstring> 5 # include <iostream> 6 using namespace STD; 7 const int imax_n = 400005; 8 int DP [imax_n]; 9 int d [imax_n]; 10 int A [imax_n]; 11 int N; 12 INT Len; 13 int max (int A, int B) 14 {15 return A> B? A: B; 16} 17 int binary_search (int K) 18 {19 int L = 0; 20 int r = Len; 21 While (L <= r) 22 {23 int mid = (L + r)/2; 24 if (d [Mid] = k) return mid; 25 if (d [Mid] <K) L = Mid + 1; 26 if (d [Mid]> K) r = mid-1; 27} 28 return l; 29} 30 void dp () 31 {32 memset (DP, 0, sizeof (DP); 33 memset (D, 0, sizeof (d); 34 Len =-1; 35 For (INT I = 0; I <n; I ++) 36 {37 Int J = binary_search (A [I]); 38 If (j> Len) len ++; 39 DP [I] = J + 1; 40 d [J] = A [I]; 41} 42 int ans = 0; 43 for (INT I = 0; I <n; I ++) 44 ans = max (ANS, DP [I]); 45 printf ("% d \ n ", ans); 46} 47 int main () 48 {49 int t; 50 scanf ("% d", & T); 51 while (t --) 52 {53 scanf ("% d", & N); 54 for (INT I = 0; I <n; I ++) 55 scanf ("% d ", & A [I]); 56 dp (); 57} 58 return 0; 59}
View code