HDU 5489 Removed Interval

题意:

求序列中切掉连续的L长度后的最长上升序列

思路:

从前到后求一遍LIS,从后往前求一遍LDS,然后枚举切开的位置i,用线段树维护区间最大值,在i~n中找到第一个比a[i - L]大的位置k,用LIS[i - L] + LDS[k]更新答案.

代码

#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#define eps 1e-8
#define INF 0x3f3f3f3f
#define LL long long
#define MAXN 500005
#define sqr(x) (x) * (x)
using namespace std;
int n, m, s;
int a[MAXN], b[MAXN], c[MAXN];
int f[MAXN], g[MAXN]; int LIS(int n){
int i, k;
k = 1;
c[1] = b[n];
g[n] = 1;
for (i = n - 1; i >= 1; i--){
if (b[i] > c[k]){
c[++k] = b[i];
g[i] = k;
}
else{
int pos = lower_bound(c + 1, c + k + 1, b[i]) - c;
c[pos] = b[i];
g[i] = pos;
}
}
return k;
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif // OPEN_FILE
int T;
scanf("%d", &T);
int cas = 1;
int n, L;
while (T--){
if (cas == 5){
cas = 5;
}
scanf("%d%d", &n, &L);
for (int i = 1; i <= n; i++){
scanf("%d", &a[i]);
b[i] = -a[i];
}
LIS(n);
int ans = 0;
int q = 0;
memset(f, INF, sizeof(f));
for (int i = L + 1; i <= n; i++){
int p = lower_bound(f + 1, f + n + 1, a[i]) - f;
ans = max(ans, p + g[i] - 1);
p = lower_bound(f + 1, f + n + 1, a[i - L]) - f;
f[p] = a[i - L];
q = max(q, p);
}
ans = max(ans, q);
printf("Case #%d: %d\n", cas++, ans);
}
}

最新文章

  1. WCF学习之旅—请求与答复模式和单向模式(十九)
  2. 基于netty轻量的高性能分布式RPC服务框架forest&lt;上篇&gt;
  3. Struts2学习笔记 - Action篇&lt;定义逻辑Action&gt;
  4. Create Volume 操作(Part III) - 每天5分钟玩转 OpenStack(52)
  5. Mac小知识(不定时更新)
  6. deeplab hole algorithm
  7. unity如何显示血条(不使用NGUI)
  8. a个人经验总结2
  9. tomcat The file is absent or does not have execute permission
  10. 如何让python程序运行得更快
  11. 迁移到MariaDB galera
  12. AndroidStudio 快捷键使用
  13. iphone 拨打电话的 两种方法-备
  14. Codis集群的搭建
  15. linux内核源码阅读之facebook硬盘加速利器flashcache
  16. Android上成功实现了蓝牙的一些Profile
  17. 使用SQLServer2005插入一条数据时返回当前插入数据的ID
  18. css3的学习
  19. 二、java基本语法
  20. Flask使用记录

热门文章

  1. uva 10641 (来当雷锋的这回....)
  2. hdu 2079 选课时间(题目已改动,注意读题) (母函数)
  3. bzoj1202: [HNOI2005]狡猾的商人(差分约束)
  4. m_Orchestrate learning system---十四、数据表中字段命名规则
  5. springmvc两种非注解的处理器适配器
  6. 找出在使用临时表空间的SQL
  7. K-D树学习笔记
  8. hdu5321 beautiful set(莫比乌斯反演)
  9. CF1015F Bracket Substring (KMP+DP)
  10. Linux系统下安装配置 OpenLDAP + phpLDAPadmin