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 ...
随机推荐
- 创建面注记PolygonElement
1.根据4点创建一个面 /// <summary> /// 根据4个点创建图形,点序要顺时针 /// </summary> /// <param name="p ...
- centos6.5安装oracle11g_2
centos7安装oracle数据库不成功,换成centos6.5安装,可以安装成功,记录一下 安装系统时,主机名如果不是用localhost,安装成功后,要用主机名和ip做映射,修改/etc/hos ...
- 2Struts2配置----青软S2SH(笔记)
实例的文件目录如下:两个配置文件(web.xml和struts.xml),一个UserAction.java,三个jsp. 1.配置Struts2应用环境: 下载Struts2的jar包,官网是:ht ...
- ORACLE 触发器
•1.1 触发器类型 • DML触发器 • 替代触发器 • 系统触发器 •1.2 创建触发器 • 触发器触发次序 • 创建DML触发器 • 创建替代(INSTEAD OF)触发器 • 创建系统事件触发 ...
- CSS-dl+dt+dd的应用(非常实用)
http://smallpig301.blog.163.com/blog/static/9986093201010262499229/
- JavaScript "自"运行-setInertval()和setTimeout()理解
setInterval()和clearInterval() var result = "Y"; function onOk() { var tid = setInterval(fu ...
- PDO 用法学习
PDO: php data object数据库访问抽象层 基于驱动:1.安装扩展 php_pdo.dll2.安装驱动 php_pdo_mysql.dll linux 编译时参数:--with-pdo= ...
- springMVC学习之接受JSON参数
今天在springmvc使用rest模式异步提交,后台接受json字符.发现好多问题,感觉和spring3.0使用习惯上多少有点区别.因此把4.0的异步提交和方式记录下来. 前台页面代码如下: < ...
- 技术架构:IBatisNet
--连接数据库框架 1 providers.config 提供配制 常用的数据库连接程序 的xml文件 2 SqlMap.xml SQL语句执行结果和实体对象之间的映射文 ...
- ABAP 传入数据到EXCEL自编函数
DATA: excel TYPE ole2_object, workbook TYPE ole2_object, sheet TYPE ole2_object, ...