Hdu 3564 Another LIS 线段树+LIS
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 1361 Accepted Submission(s): 492
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.
In the sample, we add three numbers to the sequence, and form three sequences.
a. 1
b. 2 1
c. 2 1 3
#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的更多相关文章
- hdu_3564_Another LIS(线段树+LIS)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=3564 题意:给你N个数的位置.数i的位置为第i个数,比如 0 0 2,表示1插在第0个位置,此时数列为 ...
- hdu 5700区间交(线段树)
区间交 Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submiss ...
- Snacks HDU 5692 dfs序列+线段树
Snacks HDU 5692 dfs序列+线段树 题意 百度科技园内有n个零食机,零食机之间通过n−1条路相互连通.每个零食机都有一个值v,表示为小度熊提供零食的价值. 由于零食被频繁的消耗和补充, ...
- HDU - 3564 Another LIS(LIS+线段树)
http://acm.hdu.edu.cn/showproblem.php?pid=3564 题意 给出1~n的插入顺序,要求每次插入之后的LIS 分析 首先用线段树还原出最终序列.因为插入的顺序是按 ...
- 2015合肥网络赛 HDU 5489 Removed Interval LIS+线段树(树状数组)
HDU 5489 Removed Interval 题意: 求序列中切掉连续的L长度后的最长上升序列 思路: 从前到后求一遍LIS,从后往前求一遍LDS,然后枚举切开的位置i,用线段树维护区间最大值, ...
- POJ 3903 Stock Exchange(LIS || 线段树)题解
题意:求最大上升子序列 思路:才发现自己不会LIS,用线段树写的,也没说数据范围就写了个离散化,每次查找以1~a[i]-1结尾的最大序列答案,然后更新,这样遍历一遍就行了.最近代码总是写残啊... 刚 ...
- Codeforces 486E LIS of Sequence(线段树+LIS)
题目链接:Codeforces 486E LIS of Sequence 题目大意:给定一个数组.如今要确定每一个位置上的数属于哪一种类型. 解题思路:先求出每一个位置选的情况下的最长LIS,由于開始 ...
- D. Babaei and Birthday Cake---cf629D(LIS线段树优化)
题目链接:http://codeforces.com/problemset/problem/629/D 题意就是现有n个蛋糕,蛋糕的形状是圆柱体,每个蛋糕的体积就是圆柱体的体积,每个蛋糕的编号是1-- ...
- HDU 5091---Beam Cannon(线段树+扫描线)
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=5091 Problem Description Recently, the γ galaxies bro ...
随机推荐
- BZOJ 4568 幸运数字
题目传送门 4568: [Scoi2016]幸运数字 Time Limit: 60 Sec Memory Limit: 256 MB Description A 国共有 n 座城市,这些城市由 n-1 ...
- JDK Collection 源码分析(1)—— Collection
JDK Collection JDK Collection作为一个最顶层的接口(root interface),JDK并不提供该接口的直接实现,而是通过更加具体的子接口(sub interface ...
- Python之路【第二十二篇】CMDB项目
浅谈ITIL TIL即IT基础架构库(Information Technology Infrastructure Library, ITIL,信息技术基础架构库)由英国政府部门CCTA(Central ...
- Rabbitmq Exchange Type 说明
Exchange在定义的时候是有类型的,以决定到底是哪些Queue符合条件,可以接收消息 fanout 所有bind到此exchange的queue都可以接收消息 direct 通过routingKe ...
- FireBug提示:本页面不包含 JavaScript,明明是包含js的。
本页面不包含 JavaScript 如果 <script> 标签有 "type" 属性, 其值应为 "text/javascript" 或者 &qu ...
- Linux下c开发 之 线程通信(转)
Linux下c开发 之 线程通信(转) 1.Linux“线程” 进程与线程之间是有区别的,不过Linux内核只提供了轻量进程的支持,未实现线程模型.Linux是一种“多进程单线程”的操作系统.Linu ...
- sscanf提取字符串中的数据php
1.需求 理解sscanf的作用 2.例子 $str = "age:30 weight:60kg"; sscanf($str,"age:%d weight:%dkg&qu ...
- PYTHON 深拷贝,浅拷贝
声明:本篇笔记,模仿与其它博客中的内容 浅拷贝 浅拷贝,在内存中只额外创建第一层数据 import copy n1 = {"k1": "wu", "k ...
- espcms内容页上下篇按后台手动排序号
模板文件: {%get name=plist class="did":$read.did,pid:$read.pid%} <li class="fl"&g ...
- Lua 读表代码,自动生成字段名字
表格格式为 INT STRING INT INT INT INT INT Id Desc Type SceneId OpenId MaxPliesp ClearancePlies 第1关 - 第2关 ...