题目大意:不知,根据样例猜测为最长上升子序列(竟然还对了)

题解:$O(n log_2 n)$,求二维偏序,(q为存答案的序列,a存原序列,len为答案)

for(int i = 1; i <= n; i++) {
    if(a[i] > q[len]) {q[++len]=a[i];continue;}
    *upper_bound(q, q + len, a[i]) = a[i];
}

卡点:

 

C++ Code:

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int T, n ,a;
int f[40010], cnt;
int main() {
	scanf("%d", &T);
	while (T--) {
		scanf("%d", &n);
		memset(f, 0x3f, sizeof f);
		for (int i = 0 ; i < n; i++) {
			scanf("%d", &a);
			*lower_bound(f, f + n, a) = a;
		}
		printf("%d\n",lower_bound(f, f + n, 0x3f3f3f3f) - f);
	}
	return 0;
} 

  

相关文章:

  • 2021-05-05
  • 2021-10-20
  • 2021-09-10
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-12-26
  • 2021-10-09
  • 2021-07-21
  • 2021-04-24
  • 2021-09-28
  • 2021-09-20
相关资源
相似解决方案