Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 1361    Accepted Submission(s): 492

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
 
思路:由于是从大到小插值的,那么我们只需要知道最终的序列,再对其求一遍LIS即可。可以用线段树求最终的序列,从后往前考虑,一开始有n个空位,对于每个数的插入位置a[i],其应该放在从左往右的第a[i]个空格,放完数后该空格被占用。该问题相当于给出n个数,多次操作,找出第k1个数后,将该数删去,继续找第k2个数。。。
#include <bits/stdc++.h>
using namespace std;
const int N = + ;
#define lson rt << 1, l, m
#define rson rt <<1|1, m + 1, r int num[N << ];
int a[N], pos[N], ans[N], res[N], n;
void build(int rt, int l, int r) {
num[rt] = r - l + ;
if(l == r) return ;
int m = (l + r) >> ;
build(lson);
build(rson);
}
void update(int rt, int l, int r, int k, int v) {
if(l == r) {
pos[l] = v;
num[rt] = ;
return;
}
int m = (l + r) >> ;
if(k > num[rt << ]) update(rson, k - num[rt << ], v);
else update(lson, k, v);
num[rt] = num[rt << ] + num[rt << |];
}
int LIS[N], len;
void solve() {
len = ;
LIS[] = ;
for(int i = ; i <= n; ++i) {
int p = upper_bound(LIS, LIS + len, pos[i]) - LIS - ;
LIS[p + ] = pos[i];
ans[i] = p + ;
if(p + == len) len++;
}
}
int main() {
// freopen("in.txt", "r", stdin);
int _, cas = ; scanf("%d", &_);
while(_ --) {
scanf("%d", &n);
build(, , n);
// puts("-----BUG-----"); for(int i = ; i <= n; ++i) { scanf("%d", a + i); a[i]++; }
for(int i = n; i >= ; --i) update(, , n, a[i], i);
solve();
for(int i = ; i <= n; ++i) res[ pos[i] ] = ans[i];
for(int i = ; i <= n; ++i) res[i] = max(res[i], res[i - ]);
printf("Case #%d:\n", cas++);
for(int i = ; i <= n; ++i) printf("%d\n", res[i]);
puts("");
}
}

Hdu 3564 Another LIS 线段树+LIS的更多相关文章

  1. hdu_3564_Another LIS(线段树+LIS)

    题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=3564 题意:给你N个数的位置.数i的位置为第i个数,比如 0 0 2,表示1插在第0个位置,此时数列为 ...

  2. hdu 5700区间交(线段树)

    区间交 Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submiss ...

  3. Snacks HDU 5692 dfs序列+线段树

    Snacks HDU 5692 dfs序列+线段树 题意 百度科技园内有n个零食机,零食机之间通过n−1条路相互连通.每个零食机都有一个值v,表示为小度熊提供零食的价值. 由于零食被频繁的消耗和补充, ...

  4. HDU - 3564 Another LIS(LIS+线段树)

    http://acm.hdu.edu.cn/showproblem.php?pid=3564 题意 给出1~n的插入顺序,要求每次插入之后的LIS 分析 首先用线段树还原出最终序列.因为插入的顺序是按 ...

  5. 2015合肥网络赛 HDU 5489 Removed Interval LIS+线段树(树状数组)

    HDU 5489 Removed Interval 题意: 求序列中切掉连续的L长度后的最长上升序列 思路: 从前到后求一遍LIS,从后往前求一遍LDS,然后枚举切开的位置i,用线段树维护区间最大值, ...

  6. POJ 3903 Stock Exchange(LIS || 线段树)题解

    题意:求最大上升子序列 思路:才发现自己不会LIS,用线段树写的,也没说数据范围就写了个离散化,每次查找以1~a[i]-1结尾的最大序列答案,然后更新,这样遍历一遍就行了.最近代码总是写残啊... 刚 ...

  7. Codeforces 486E LIS of Sequence(线段树+LIS)

    题目链接:Codeforces 486E LIS of Sequence 题目大意:给定一个数组.如今要确定每一个位置上的数属于哪一种类型. 解题思路:先求出每一个位置选的情况下的最长LIS,由于開始 ...

  8. D. Babaei and Birthday Cake---cf629D(LIS线段树优化)

    题目链接:http://codeforces.com/problemset/problem/629/D 题意就是现有n个蛋糕,蛋糕的形状是圆柱体,每个蛋糕的体积就是圆柱体的体积,每个蛋糕的编号是1-- ...

  9. HDU 5091---Beam Cannon(线段树+扫描线)

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=5091 Problem Description Recently, the γ galaxies bro ...

随机推荐

  1. centos7下 安装mysql

    wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm rpm -ivh mysql-community-rele ...

  2. C#内存管理与垃圾回收

    垃圾回收还得从根说起,就像生儿育女一样. 根:根是一个位置,存放一个指针,该指针指向托管堆中的一个对象,或是一个空指针不指向任何对象,即为null.根存在线程栈或托管堆中,大部分的跟都在线程栈上,因为 ...

  3. 浅谈Android中拍照、从相册选择图片并截图相关知识点

    前言 我们在Android开发中经常会需要使用相机或者从相册中选取图片的情况,今天就把这里面相关的知识点总结下,方便以后开发的时候使用. 1.相机拍照并可自定义截图功能 我们先来看如何使用Intent ...

  4. Java多线程编程核心技术---学习分享

    继承Thread类实现多线程 public class MyThread extends Thread { @Override public void run() { super.run(); Sys ...

  5. Android 实现分页(使用TabWidget/TabHost)

    注:本文为转载,但该内容本人已亲身尝试,确认该方法可行,代码有点小的改动,转载用作保存与分享. 原作者地址:http://gundumw100.iteye.com/blog/853967 个人吐嘈:据 ...

  6. 2013成都网络赛 C We Love MOE Girls(水题)

    We Love MOE Girls Time Limit: 1000/500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  7. 在GridView隐藏字段

    在GridView中隐藏一字段,方便这条记录的处理,同时隐藏一个Button实现点击这条记录时的处理 1.绑定 <asp:TemplateField>                    ...

  8. PHP获取当前页面的URL

    /** * 获取当前页面完整URL地址 * * @author 52php.cnblogs.com */ function http_get_page_url() { global $_G; if ( ...

  9. HMTL判断ie版本

    html判断IE版本 1. <!--[if !IE]><!--> 除IE外都可识别 <!--<![endif]--> 2. <!--[if IE]> ...

  10. Add Two Numbers LeetCode Java

    You are given two linked lists representing two non-negative numbers. The digits are stored in rever ...