2015合肥网络赛 HDU 5489 Removed Interval LIS+线段树(树状数组)
2024-08-24 21:58:21
题意:
求序列中切掉连续的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);
}
}
最新文章
- WCF学习之旅—请求与答复模式和单向模式(十九)
- 基于netty轻量的高性能分布式RPC服务框架forest<;上篇>;
- Struts2学习笔记 - Action篇<;定义逻辑Action>;
- Create Volume 操作(Part III) - 每天5分钟玩转 OpenStack(52)
- Mac小知识(不定时更新)
- deeplab hole algorithm
- unity如何显示血条(不使用NGUI)
- a个人经验总结2
- tomcat The file is absent or does not have execute permission
- 如何让python程序运行得更快
- 迁移到MariaDB galera
- AndroidStudio 快捷键使用
- iphone 拨打电话的 两种方法-备
- Codis集群的搭建
- linux内核源码阅读之facebook硬盘加速利器flashcache
- Android上成功实现了蓝牙的一些Profile
- 使用SQLServer2005插入一条数据时返回当前插入数据的ID
- css3的学习
- 二、java基本语法
- Flask使用记录
热门文章
- uva 10641 (来当雷锋的这回....)
- hdu 2079 选课时间(题目已改动,注意读题) (母函数)
- bzoj1202: [HNOI2005]狡猾的商人(差分约束)
- m_Orchestrate learning system---十四、数据表中字段命名规则
- springmvc两种非注解的处理器适配器
- 找出在使用临时表空间的SQL
- K-D树学习笔记
- hdu5321 beautiful set(莫比乌斯反演)
- CF1015F Bracket Substring (KMP+DP)
- Linux系统下安装配置 OpenLDAP + phpLDAPadmin