Another LIS

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 1291    Accepted Submission(s): 451

Problem Description
There is a sequence firstly empty. We begin to add number from 1 to N to the sequence, and every time we just add a single number to the sequence at a specific position. Now, we want to know length of the LIS (Longest Increasing Subsequence) after every time's
add.
 
Input
An integer T (T <= 10), indicating there are T test cases.

For every test case, an integer N (1 <= N <= 100000) comes first, then there are N numbers, the k-th number Xk means that we add number k at position Xk (0 <= Xk <= k-1).See hint for more details.
 
Output
For the k-th test case, first output "Case #k:" in a separate line, then followed N lines indicating the answer. Output a blank line after every test case.
 
Sample Input
1
3
0 0 2
 
Sample Output
Case #1:
1
1
2
Hint
In the sample, we add three numbers to the sequence, and form three sequences.
a. 1
b. 2 1
c. 2 1 3
 
Author
standy
 
Source
 
Recommend
思路:就是从左插入找空位,从1~n用线段树记录他们的位置。然后再对他们的位置进行LIS就好
ac代码
#include<stdio.h>
#include<string.h>
#define max(a,b) (a>b?a:b)
int a[100010];
int node[100010<<2],d[100010],len,dp[100010];
void build(int l,int r,int tr)
{
node[tr]=r-l+1;
if(l==r)
return;
int mid=(l+r)>>1;
build(l,mid,tr<<1);
build(mid+1,r,tr<<1|1);
node[tr]=node[tr<<1]+node[tr<<1|1];
}
int bin(int x)
{
int l=1,r=len;
while(l<=r)
{
int mid=(l+r)>>1;
if(x>dp[mid])
l=mid+1;
else
r=mid-1;
}
return l;
}
void insert(int pos,int num,int l,int r,int tr)
{
if(l==r)
{
d[num]=l;
node[tr]=0;
return;
}
int mid=(l+r)>>1;
node[tr]--;
if(pos<=node[tr<<1])
{
insert(pos,num,l,mid,tr<<1);
}
else
insert(pos-node[tr<<1],num,mid+1,r,tr<<1|1);
}
int main()
{
int t,c=0;
scanf("%d",&t);
while(t--)
{
int n;
scanf("%d",&n);
int i;
for(i=1;i<=n;i++)
{
scanf("%d",&a[i]);
dp[i]=0;
}
build(1,n,1);
for(i=n;i>0;i--)
{
insert(a[i]+1,i,1,n,1);
}
len=0;
/*for(i=1;i<=n;i++)
{
printf("%d\n",d[i]);
}*/
printf("Case #%d:\n",++c);
for(i=1;i<=n;i++)
{
int k=bin(d[i]);
len=max(len,k);
dp[k]=d[i];
printf("%d\n",len);
}
printf("\n");
}
}

 

HDOJ 题目3564 Another LIS(线段树单点更新,LIS)的更多相关文章

  1. HDU 1754 I Hate It 线段树单点更新求最大值

    题目链接 线段树入门题,线段树单点更新求最大值问题. #include <iostream> #include <cstdio> #include <cmath> ...

  2. HDU 1166 敌兵布阵(线段树单点更新)

    敌兵布阵 单点更新和区间更新还是有一些区别的,应该注意! [题目链接]敌兵布阵 [题目类型]线段树单点更新 &题意: 第一行一个整数T,表示有T组数据. 每组数据第一行一个正整数N(N< ...

  3. poj 2892---Tunnel Warfare(线段树单点更新、区间合并)

    题目链接 Description During the War of Resistance Against Japan, tunnel warfare was carried out extensiv ...

  4. HDU 1166 敌兵布阵(线段树单点更新,板子题)

    敌兵布阵 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submi ...

  5. POJ 1804 Brainman(5种解法,好题,【暴力】,【归并排序】,【线段树单点更新】,【树状数组】,【平衡树】)

    Brainman Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 10575   Accepted: 5489 Descrip ...

  6. POJ.3321 Apple Tree ( DFS序 线段树 单点更新 区间求和)

    POJ.3321 Apple Tree ( DFS序 线段树 单点更新 区间求和) 题意分析 卡卡屋前有一株苹果树,每年秋天,树上长了许多苹果.卡卡很喜欢苹果.树上有N个节点,卡卡给他们编号1到N,根 ...

  7. hdu 2795 Billboard 线段树单点更新

    Billboard Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=279 ...

  8. hdu1166(线段树单点更新&区间求和模板)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1166 题意:中文题诶- 思路:线段树单点更新,区间求和模板 代码: #include <iost ...

  9. hdu 1166 敌兵布阵 (线段树单点更新)

    敌兵布阵                                                         Time Limit: 2000/1000 MS (Java/Others)  ...

  10. HDU 1166 敌兵布阵(线段树单点更新,区间查询)

    描述 C国的死对头A国这段时间正在进行军事演习,所以C国间谍头子Derek和他手下Tidy又开始忙乎了.A国在海岸线沿直线布置了N个工兵营地,Derek和Tidy的任务就是要监视这些工兵营地的活动情况 ...

随机推荐

  1. hdu 1548(最短路)

    A strange lift Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)To ...

  2. Eclipse 导入项目乱码问题

    1.编码不对 a.对某文件或某工程更改编码: 鼠标移到工程名或文件名,右键->Properties->Resource->Text file enCoding ->更改编码(G ...

  3. DOM-window下的常用子对象-location-刷新页面

    1.刷新当前页面:(通过给location.href赋值的方式) window.location.href="" eg:window.location.href="htt ...

  4. Thinkphp3.2.3的主从分离事务问题(坑!!!)

    情景:使用Thinkphp3.2.3在项目开发中发现开启主从分离后,一旦事务体内,同时存在写入再读出,再写入这样的操作,TP在识别数据库的时候把读操作和写操作识别到了两个库..实际上希望事务开启后,所 ...

  5. Kali Linux 2017中Scapy运行bug解决

    Kali Linux 2017中Scapy运行bug解决   Scapy是一款强大的网络数据包构建工具.在Kali Linux 2017中,当在scapy的命令行中,运行res.graph()生成图形 ...

  6. Autolayout 01

    Auto Layout Concepts auto layout的基本概念是constraint(约束).表示了你interface中的layout元素.例如,你可以创建一个约束来指定元素的宽度或者距 ...

  7. Android Studio +MAT 分析内存泄漏实战

    对于内存泄漏,在Android中如果不注意的话,还是很容易出现的,尤其是在Activity中,比较容易出现,下面我就说下自己是如何查找内存泄露的. 首先什么是内存泄漏? 内存泄漏就是一些已经不使用的对 ...

  8. angular js 使用$location问题整理

    angular js 自带的$location方法十分强大,通过使用$location方法.我们能够获取到server的port.杂乱连接中的path()部分(/所包括的部分). 例: // give ...

  9. VC++动态链接库(DLL)编程深入浅出(二)

    好,让我们正式进入动态链接库的世界,先来看看最一般的DLL,即非MFC DLL 上节给大家介绍了静态链接库与库的调试与查看,本节主要介绍非MFC DLL. 4.非MFC DLL 4.1一个简单的DLL ...

  10. Oracle内存管理(之五)

    [深入解析--eygle]学习笔记 1.4. 2其它内存组件 Large Pool-大池是SGA的一个可选组件,通经常使用于共享server模式(MTS). 并行计算或 RMAN的备份恢复等操作. J ...