cdq分治,dp(i)表示以i为结尾的最长LIS,那么dp的递推是依赖于左边的。

因此在分治的时候需要利用左边的子问题来递推右边。

(345ms? 区间树TLE

/*********************************************************
* ------------------ *
* author AbyssFish *
**********************************************************/
#include<cstdio>
#include<iostream>
#include<string>
#include<cstring>
#include<queue>
#include<vector>
#include<stack>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<cmath>
#include<numeric>
using namespace std; const int MAX_N = +; int dp[MAX_N];
int x[MAX_N], y[MAX_N];
int ys[MAX_N];
int id[MAX_N];
int N; int ns; int *cur;
bool cmp(int a,int b)
{
return cur[a] < cur[b] || (cur[a] == cur[b] && a > b);//这是为了保证严格的单调性
} int compress(int *r, int *dat, int *a, int n)
{
for(int i = ; i < n; i++){
r[i] = i;
}
cur = dat;
sort(r,r+n,cmp);
a[r[]] = ;
for(int i = ; i < n; i++){
int k = r[i], p = r[i-];
a[k] = dat[k] == dat[p]?a[p]:a[p]+;
}
return a[r[n-]];
} int C[MAX_N]; void add(int yi,int d)
{
while(yi <= ns){
C[yi] = max(C[yi],d);
yi += yi&-yi;
}
} int mx_pfx(int yi)
{
int re = ;
while(yi > ){
re = max(C[yi],re);
yi &= yi-;
}
return re;
} void clr(int yi)
{
while(yi <= ns){
C[yi] = ;
yi += yi&-yi;
}
} void dv(int l, int r)
{
if(r-l <= ){
dp[l]++;
}
else {
int md = (l+r)>>;
dv(l,md); for(int i = l; i < r; i++) id[i] = i;
sort(id+l,id+r,cmp); //x维度 for(int i = l; i < r; i++){
int k = id[i];
if(k < md){ //position 维度
add(ys[k],dp[k]); //BIT下标是 y维度
}
else {
//查询位置前保证了BIT里的元素, 位置md之前,x严格小于待查元素
dp[k] = max(dp[k], mx_pfx(ys[k]-));//y严格小于待查元素的最大dp值
}
} for(int i = l; i < r; i++){
if(id[i] < md)
clr(ys[id[i]]);
}
dv(md,r);
}
} void solve()
{
scanf("%d",&N);
for(int i = ; i < N; i++){
scanf("%d%d",x+i,y+i);
}
ns = compress(id,y,ys,N);
cur = x;
dv(,N);
printf("%d\n",*max_element(dp,dp+N));
} //#define LOCAL
int main()
{
#ifdef LOCAL
freopen("in.txt","r",stdin);
#endif
solve();
return ;
}

SPOJ - LIS2 Another Longest Increasing Subsequence Problem的更多相关文章

  1. SPOJ LIS2 Another Longest Increasing Subsequence Problem 三维偏序最长链 CDQ分治

    Another Longest Increasing Subsequence Problem Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://a ...

  2. SPOJ LIS2 - Another Longest Increasing Subsequence Problem(CDQ分治优化DP)

    题目链接  LIS2 经典的三维偏序问题. 考虑$cdq$分治. 不过这题的顺序应该是 $cdq(l, mid)$ $solve(l, r)$ $cdq(mid+1, r)$ 因为有个$DP$. #i ...

  3. [BZOJ2225][SPOJ2371]LIS2 - Another Longest Increasing Subsequence Problem:CDQ分治+树状数组+DP

    分析 这回试了一下三级标题,不知道效果怎么样? 回到正题,二维最长上升子序列......嗯,我会树套树. 考虑\(CDQ\)分治,算法流程: 先递归进入左子区间. 将左,右子区间按\(x\)排序. 归 ...

  4. SPOJ Another Longest Increasing Subsequence Problem 三维最长链

    SPOJ Another Longest Increasing Subsequence Problem 传送门:https://www.spoj.com/problems/LIS2/en/ 题意: 给 ...

  5. SPOJ:Another Longest Increasing Subsequence Problem(CDQ分治求三维偏序)

    Given a sequence of N pairs of integers, find the length of the longest increasing subsequence of it ...

  6. [LintCode] Longest Increasing Subsequence 最长递增子序列

    Given a sequence of integers, find the longest increasing subsequence (LIS). You code should return ...

  7. 【Lintcode】076.Longest Increasing Subsequence

    题目: Given a sequence of integers, find the longest increasing subsequence (LIS). You code should ret ...

  8. LintCode刷题笔记--Longest Increasing Subsequence

    标签: 动态规划 描述: Given a sequence of integers, find the longest increasing subsequence (LIS). You code s ...

  9. [LeetCode] Longest Increasing Subsequence

    Longest Increasing Subsequence Given an unsorted array of integers, find the length of longest incre ...

随机推荐

  1. Go语言基础之1--标识符、关键字、变量和常量、数据类型、Go的基本程序结构、Golang的特性

    一.前言 当我们项目较为简单时,我们在src目录下新建一个该项目目录,里面存放源码文件即可,见下图: 当我们一个项目较为复杂时,我们可以在src目录下新建一个该项目目录,在针对该项目不同模块创建不同目 ...

  2. Go语言基础环境配置(windows)

    一.基础软件包安装 需要安装go环境包.git.IDE(VScode),安装包见下图: 1.1 安装go windows环境直接双击安装包安装即可,在cmd窗口输入go,结果如下图所示即表示安装成功: ...

  3. Dev GridView RowCellClick事件与MouseDown事件

    GridView处于可编辑状态,左键点击默认为“进入编辑”. 将GridView的OptionsColumn.AllowEdit设置为false后左键可触发RowCellClick.但有时候,既希望G ...

  4. webpack01

  5. g++ -I(大写i) 与-L(大写l)-l(小写l) 的作用与学习

    linux 下 g++编译程序时,-I(大写i) 与-L(大写l)-l(小写l) 的作用 作为一个linux入门级使用者,gcc/g++ 的简单操作已经用过多次, 但是有时稍微复杂一点的程序就会使用到 ...

  6. Readthedocs+Github搭建文档

    一.文档撰写前提 环境部署: > git clone https://github.com/toooney/demo-readthedocs.git > pip install sphin ...

  7. 性能测试工具LoadRunner32-LR之windows性能监控Perfmon

    Perfmon是啥? Perfmon提供了图表化的系统性能实时监视器.性能日志和警报管理,可以用于监视CPU使用率.内存使用率.硬盘读写速度.网络速度等 性能分析方法 内存分析方法 内存分析用于判断系 ...

  8. .NET标准化题目

    1. 下面对FxCop的描述中,错误的是:(D) A. FxCop是一个静态代码分析工具. B. 可以定制自己的规则加入FxCop引擎. C. FxCop主要是对.NET中托管代码的assembly进 ...

  9. Kudu Tablet design

    不多说,直接上干货! http://blog.csdn.net/lookqlp/article/details/51416829

  10. jQuery源码浅析2–奇技淫巧

    最近一直在研读 jQuery 源码,初看源码一头雾水毫无头绪,真正静下心来细看写的真是精妙,让你感叹代码之美. 其结构明晰,高内聚.低耦合,兼具优秀的性能与便利的扩展性,在浏览器的兼容性(功能缺陷.渐 ...