Code:

  1. #include <cstdio>
  2. #include <algorithm>
  3. #include <cstring>
  4. #define maxn 200000
  5. #define setIO(s) freopen(s".in","r",stdin)
  6. using namespace std;
  7. int n,ans[maxn],hh[maxn];
  8. inline void getmax(int &a,int b){ if(b>a)a=b; }
  9. struct Node{
  10. int x,y,z,org;
  11. }node[maxn];
  12. int cmpx(Node a,Node b)
  13. {
  14. if(a.x==b.x&&a.y==b.y) return a.z<b.z;
  15. else if(a.x==b.x) return a.y<b.y;
  16. else return a.x<b.x;
  17. }
  18. int cmpy(Node a,Node b){
  19. if(a.y==b.y) return a.z<b.z;
  20. else return a.y<b.y;
  21. }
  22. struct BIT{
  23. int C[maxn];
  24. int lowbit(int t) { return t&(-t);}
  25. void update(int p,int x){ while(p<maxn) getmax(C[p],x),p+=lowbit(p); }
  26. int query(int p){
  27. if(p<=0) return 0;
  28. int ss=0;
  29. while(p>0) getmax(ss,C[p]),p-=lowbit(p);
  30. return ss;
  31. }
  32. void del(int p){ while(p<maxn)C[p]=0,p+=lowbit(p); }
  33. }tree;
  34. void solve(int l,int r){
  35. if(l>=r) return;
  36. int mid=(l+r)>>1,tl=l,tr=mid+1;
  37. solve(l,mid);
  38. sort(node+l,node+mid+1,cmpy),sort(node+mid+1,node+r+1,cmpy);
  39.  
  40. while(tl<=mid&&tr<=r) {
  41. if(node[tl].y<node[tr].y) {
  42. tree.update(node[tl].z,ans[node[tl].org]);
  43. ++tl;
  44. }
  45. else {
  46. getmax(ans[node[tr].org],tree.query(node[tr].z-1)+1);
  47. ++tr;
  48. }
  49. }
  50. for(int i=tr;i<=r;++i) getmax(ans[node[i].org],tree.query(node[i].z-1)+1);
  51. for(int i=l;i<=mid;++i) tree.del(node[i].z);
  52. sort(node+mid+1,node+1+r,cmpx),solve(mid+1,r);
  53. }
  54.  
  55. int main(){
  56. //setIO("input");
  57. scanf("%d",&n);
  58. 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;
  59. sort(hh+1,hh+1+n);
  60. for(int i=1;i<=n;++i) node[i].z=lower_bound(hh+1,hh+1+n,node[i].z)-hh;
  61. for(int i=1;i<=n;++i) ans[i]=1;
  62. sort(node+1,node+1+n,cmpx);
  63. solve(1,n);
  64. int h=0;
  65. for(int i=1;i<=n;++i) getmax(h,ans[i]);
  66. printf("%d",h);
  67. return 0;
  68. }

  

BZOJ2225: [Spoj 2371]Another Longest Increasing CDQ分治,3维LIS的更多相关文章

  1. 【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 ...

  2. BZOJ 2225: [Spoj 2371]Another Longest Increasing (CDQ分治+dp)

    题面 Description 给定N个数对(xi, yi),求最长上升子序列的长度.上升序列定义为{(xi, yi)}满足对i<j有xi<xj且yi<yj. Input Output ...

  3. BZOJ 2225 [Spoj 2371]Another Longest Increasing(CDQ分治)

    [题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=2225 [题目大意] 给定N个数对(xi,yi),求最长上升子序列的长度. 上升序列定义 ...

  4. bzoj 2225 [Spoj 2371]Another Longest Increasing

    这道题 连续上升的三元组 且已经按照第一维排好序了. 直接上CDQ分治即可 当然也是可以2-Dtree解决这个 问题 但是感觉nlog^2 比nsqrt(n)要快一些.. 算是复习一发CDQ分治吧 也 ...

  5. BZOJ_2225_[Spoj 2371]Another Longest Increasing_CDQ 分治+树状数组

    BZOJ_2225_[Spoj 2371]Another Longest Increasing_CDQ 分治+树状数组 Description        给定N个数对(xi, yi),求最长上升子 ...

  6. HDU4742 CDQ分治,三维LIS

    HDU4742 CDQ分治,三维LIS 传送门:http://acm.hdu.edu.cn/showproblem.php?pid=4742 题意: 每个球都有三个属性值x,y,z,要求最长的lis的 ...

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

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

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

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

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

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

随机推荐

  1. python写的爬虫工具,抓取行政村的信息并写入到hbase里

    python的版本是2.7.10,使用了两个第三方模块bs4和happybase,可以通过pip直接安装. 1.logger利用python自带的logging模块配置了一个简单的日志输出 2.get ...

  2. js 基本基础知识回顾

    js中的一切的变量.函数.操作符等等都是区分大小写的. js的基本的数据类型->包含下面的5种: 1.undefined 2.Null 3.Boolean 4.Number 5.String j ...

  3. HDU 1257 最少拦截系统【最长上升子序列】

    解题思路:可以转化为求最长上升子序列来做,还是可以用an与按升序排列后的an求LCS来做,为防止超时,用滚动数组优化一下就可以了. 最少拦截系统 Time Limit: 2000/1000 MS (J ...

  4. Imperative programming

    In computer science, imperative programming is a programming paradigm that uses statements that chan ...

  5. 脑图工具MindNode"附属节点"是什么意思 图解

    新手会发现在主节点上无论是按Tab子节点还是按Enter附属节点,都是向右延伸,感觉像没区别? 其实不然,从第二个节点开始,你再按 Tab 或者 Enter 就知道区别了. 废话少说,直接上图. 我觉 ...

  6. CentOS 6.5下部署日志服务器 Rsyslog+LogAnalyzer+MySQL

    简介 LogAnalyzer 是一款syslog日志和其他网络事件数据的Web前端.它提供了对日志的简单浏览.搜索.基本分析和一些图表报告的功能.数据可以从数据库或一般的syslog文本文件中获取,所 ...

  7. mysql定时清理binlog

    一.没有主从同步的情况下清理日志 mysql -uroot -p123456 -e 'PURGE MASTER LOGS BEFORE DATE_SUB( NOW( ),INTERVAL 5 DAY) ...

  8. Eclipse中使用GIT将已提交到本地的文件上传至远程仓库

    GIT将已提交到本地的文件上传至远程仓库: 1.  右击项目——Team——Push to Upstream,即可将已保存在本地的文件上传推至GIT远程仓库.

  9. myeclipse 字体设置为UTF-8

    将myeclipse设置成utf-8格式的方式如下: 1.windows->Preferences打开"首选项"对话框,如图: 2.点击左侧导航树,导航到general-&g ...

  10. 最全mysql的复制和读写分离

    mysql的复制和mysql的读写分离从来就不是一个简单的话题,今天笔者就详细来记录一下我学习的mysql.   mysql日至类型有:二进制日志,事务日志,错误日志,一般查询日志,中继日志,慢查询日 ...