BZOJ2225: [Spoj 2371]Another Longest Increasing CDQ分治,3维LIS
Code:
#include <cstdio>
#include <algorithm>
#include <cstring>
#define maxn 200000
#define setIO(s) freopen(s".in","r",stdin)
using namespace std;
int n,ans[maxn],hh[maxn];
inline void getmax(int &a,int b){ if(b>a)a=b; }
struct Node{
int x,y,z,org;
}node[maxn];
int cmpx(Node a,Node b)
{
if(a.x==b.x&&a.y==b.y) return a.z<b.z;
else if(a.x==b.x) return a.y<b.y;
else return a.x<b.x;
}
int cmpy(Node a,Node b){
if(a.y==b.y) return a.z<b.z;
else return a.y<b.y;
}
struct BIT{
int C[maxn];
int lowbit(int t) { return t&(-t);}
void update(int p,int x){ while(p<maxn) getmax(C[p],x),p+=lowbit(p); }
int query(int p){
if(p<=0) return 0;
int ss=0;
while(p>0) getmax(ss,C[p]),p-=lowbit(p);
return ss;
}
void del(int p){ while(p<maxn)C[p]=0,p+=lowbit(p); }
}tree;
void solve(int l,int r){
if(l>=r) return;
int mid=(l+r)>>1,tl=l,tr=mid+1;
solve(l,mid);
sort(node+l,node+mid+1,cmpy),sort(node+mid+1,node+r+1,cmpy); while(tl<=mid&&tr<=r) {
if(node[tl].y<node[tr].y) {
tree.update(node[tl].z,ans[node[tl].org]);
++tl;
}
else {
getmax(ans[node[tr].org],tree.query(node[tr].z-1)+1);
++tr;
}
}
for(int i=tr;i<=r;++i) getmax(ans[node[i].org],tree.query(node[i].z-1)+1);
for(int i=l;i<=mid;++i) tree.del(node[i].z);
sort(node+mid+1,node+1+r,cmpx),solve(mid+1,r);
} int main(){
//setIO("input");
scanf("%d",&n);
for(int i=1;i<=n;++i) node[i].x=node[i].org=i,scanf("%d%d",&node[i].y,&node[i].z),hh[i]=node[i].z;
sort(hh+1,hh+1+n);
for(int i=1;i<=n;++i) node[i].z=lower_bound(hh+1,hh+1+n,node[i].z)-hh;
for(int i=1;i<=n;++i) ans[i]=1;
sort(node+1,node+1+n,cmpx);
solve(1,n);
int h=0;
for(int i=1;i<=n;++i) getmax(h,ans[i]);
printf("%d",h);
return 0;
}
BZOJ2225: [Spoj 2371]Another Longest Increasing CDQ分治,3维LIS的更多相关文章
- 【bzoj2225】[Spoj 2371]Another Longest Increasing CDQ分治+树状数组
题目描述 给定N个数对(xi, yi),求最长上升子序列的长度.上升序列定义为{(xi, yi)}满足对i<j有xi<xj且yi<yj. 样例输入 8 1 3 3 2 1 1 4 5 ...
- BZOJ 2225: [Spoj 2371]Another Longest Increasing (CDQ分治+dp)
题面 Description 给定N个数对(xi, yi),求最长上升子序列的长度.上升序列定义为{(xi, yi)}满足对i<j有xi<xj且yi<yj. Input Output ...
- BZOJ 2225 [Spoj 2371]Another Longest Increasing(CDQ分治)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=2225 [题目大意] 给定N个数对(xi,yi),求最长上升子序列的长度. 上升序列定义 ...
- bzoj 2225 [Spoj 2371]Another Longest Increasing
这道题 连续上升的三元组 且已经按照第一维排好序了. 直接上CDQ分治即可 当然也是可以2-Dtree解决这个 问题 但是感觉nlog^2 比nsqrt(n)要快一些.. 算是复习一发CDQ分治吧 也 ...
- BZOJ_2225_[Spoj 2371]Another Longest Increasing_CDQ 分治+树状数组
BZOJ_2225_[Spoj 2371]Another Longest Increasing_CDQ 分治+树状数组 Description 给定N个数对(xi, yi),求最长上升子 ...
- HDU4742 CDQ分治,三维LIS
HDU4742 CDQ分治,三维LIS 传送门:http://acm.hdu.edu.cn/showproblem.php?pid=4742 题意: 每个球都有三个属性值x,y,z,要求最长的lis的 ...
- SPOJ LIS2 Another Longest Increasing Subsequence Problem 三维偏序最长链 CDQ分治
Another Longest Increasing Subsequence Problem Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://a ...
- SPOJ LIS2 - Another Longest Increasing Subsequence Problem(CDQ分治优化DP)
题目链接 LIS2 经典的三维偏序问题. 考虑$cdq$分治. 不过这题的顺序应该是 $cdq(l, mid)$ $solve(l, r)$ $cdq(mid+1, r)$ 因为有个$DP$. #i ...
- [BZOJ2225][SPOJ2371]LIS2 - Another Longest Increasing Subsequence Problem:CDQ分治+树状数组+DP
分析 这回试了一下三级标题,不知道效果怎么样? 回到正题,二维最长上升子序列......嗯,我会树套树. 考虑\(CDQ\)分治,算法流程: 先递归进入左子区间. 将左,右子区间按\(x\)排序. 归 ...
随机推荐
- pixhawk入门知识
Pixhawk是一种先进的自动驾驶仪,由PX4开放硬件项目设计和3D机器人制造.它具有来自ST公司先进的处理器和传感器技术,以及NuttX实时操作系统,能够实现惊人的性能,灵活性和可靠性控制任何自主飞 ...
- WCF(二)配置文件
上篇文章中对WCF的配置放到App.config中,这样可以使程序更灵活.更具有扩展性. 下面说下配置文件中各个节点的含义. 服务端: WCF配置文件节点放在<system.serviceMod ...
- Java从入门到精通一步到位!
Java作为近几年来非常火的编程语言,转行来做Java的人不计其数,但如今真正的人才仍然匮乏,所以学习Java一定要有一个系统的学习规划课程.阿里云大学帮您规划Java学习路线可以帮助您从一个小白成长 ...
- HTML 捕获window.close() 并做窗口关闭前的处理工作
转自:http://www.xinotes.net/notes/note/261/ <html> <head> <script language="JavaSc ...
- [JZOJ]100047. 【NOIP2017提高A组模拟7.14】基因变异
21 世纪是生物学的世纪,以遗传与进化为代表的现代生物理论越来越多的 进入了我们的视野. 如同大家所熟知的,基因是遗传因子,它记录了生命的基本构造和性能. 因此生物进化与基因的变异息息相关,考察基因变 ...
- ubuntu/wireshark --Lua: Error during loading: [string "/usr/share/wireshark/init.lua"]:45问题解决
错误如下: 解决方案:修改init.lua 直接运行wireshark的话会报错: Lua: Error during loading:[string "/usr/share/wiresha ...
- Unity WWW类调用http
1.Http请求中Content-Type讲解 MediaType,即是Internet Media Type,互联网媒体类型:也叫做MIME类型,在Http协议消息头中,使用Content-Type ...
- 循环语句第2种 WHILE ... LOOP END LOOP;
--------第2种-------- WHILE ... LOOP END LOOP; declare n number(3) :=1; begin WHILE n&l ...
- Windows下面使用curl
Windows下面使用curl 学习了:https://www.cnblogs.com/xing901022/p/4652624.html 下载地址:https://curl.haxx.se/down ...
- 随心所欲生成git仓库随意一段commit的专用patch应用小实践
随心所欲生成git仓库随意一段commit的专用patch应用小实践 我们在开发中.时不时的可能要去做一个patch给你的下线,或者你的合作者.在git管理中,我们知道有git format-pat ...