题意:三维空间内 n个小球,对应坐标(x,y,z)。输出LIS的长度以及方案数。

首先可以先按x排序,先降低一维,然后 剩下y 、z,在y上进行CDQ分治,按y的大小用前面的更新后面的。z方向离散化之后用树状数组维护就可以了。

  1. #include <set>
  2. #include <map>
  3. #include <cmath>
  4. #include <ctime>
  5. #include <queue>
  6. #include <stack>
  7. #include <cstdio>
  8. #include <string>
  9. #include <vector>
  10. #include <cstdlib>
  11. #include <cstring>
  12. #include <iostream>
  13. #include <algorithm>
  14. using namespace std;
  15. typedef unsigned long long ull;
  16. typedef long long ll;
  17. const int inf = 0x3f3f3f3f;
  18. const double eps = 1e-;
  19. const int maxn = 1e5+;
  20. const int mod = << ;
  21. struct Ball
  22. {
  23. int x,y,z,idx;
  24. bool operator < (const Ball &rhs)const
  25. {
  26. return x < rhs.x || (x == rhs.x && y < rhs.y) || (x == rhs.x && y == rhs.y && z < rhs.z);
  27. }
  28. } ball[maxn],tmpball[maxn];
  29. struct DP
  30. {
  31. int len,cnt;
  32. DP(){}
  33. DP(int _len,int _cnt):
  34. len(_len),cnt(_cnt) {}
  35. } dp[maxn],c[maxn];
  36. int vec[maxn],idx;
  37. inline int lowbit (int x)
  38. {
  39. return x & -x;
  40. }
  41. inline void update (DP &dp1, DP &dp2)
  42. {
  43. if (dp1.len < dp2.len)
  44. dp1 = dp2;
  45. else if (dp1.len == dp2.len)
  46. dp1.cnt += dp2.cnt;
  47. }
  48. inline void modify(int x,DP &d)
  49. {
  50. while (x <= idx)
  51. {
  52. update(c[x],d);
  53. x += lowbit(x);
  54. }
  55. }
  56. DP query(int x)
  57. {
  58. DP ans = DP (,);
  59. while (x)
  60. {
  61. update(ans,c[x]);
  62. x -= lowbit(x);
  63. }
  64. return ans;
  65. }
  66. inline void CLR(int x)
  67. {
  68. while (x <= idx)
  69. {
  70. c[x] = DP(,);
  71. x += lowbit(x);
  72. }
  73. }
  74. void CDQ (int l, int r)
  75. {
  76. if (l == r)
  77. return ;
  78. int mid = (l + r) >> ;
  79. CDQ (l, mid);
  80. for (int i = l; i <= r; i++)
  81. {
  82. tmpball[i] = ball[i];
  83. tmpball[i].x = ;
  84. }
  85. sort(tmpball+l,tmpball+r+);
  86. for (int i = l; i <= r; i++)
  87. {
  88. if (tmpball[i].idx <= mid)
  89. {
  90. modify(tmpball[i].z,dp[tmpball[i].idx]);
  91. }
  92. else
  93. {
  94. DP tmp = query(tmpball[i].z);
  95. tmp.len++;
  96. update(dp[tmpball[i].idx],tmp);
  97. }
  98. }
  99. for (int i = l; i <= r; i++)
  100. {
  101. if (tmpball[i].idx <= mid)
  102. {
  103. CLR(tmpball[i].z);
  104. }
  105. }
  106. CDQ (mid+, r);
  107. }
  108. int main(void)
  109. {
  110. #ifndef ONLINE_JUDGE
  111. freopen("in.txt","r",stdin);
  112. #endif
  113. int T, n;
  114. scanf ("%d",&T);
  115. while (T--)
  116. {
  117. scanf ("%d",&n);
  118. for (int i = ; i <= n; i++)
  119. {
  120. scanf ("%d%d%d",&ball[i].x, &ball[i].y, &ball[i].z);
  121. vec[i-] = ball[i].z;
  122. }
  123. sort (ball+, ball+n+);
  124. sort (vec,vec+n);
  125. idx = unique(vec,vec+n) - vec;
  126. for (int i = ; i <= n ; i++)
  127. {
  128. ball[i].z = lower_bound(vec,vec+idx,ball[i].z) - vec + ;
  129. ball[i].idx = i;
  130. dp[i] = DP(,);
  131. }
  132. CDQ(,n);
  133. DP ans = DP(,);
  134. for (int i = ; i <= n ;i++)
  135. {
  136. update(ans,dp[i]);
  137. }
  138. printf("%d %d\n",ans.len, ans.cnt % mod);
  139. }
  140. return ;
  141. }

HDU4742----Pinball Game 3D(三维LIS、CDQ分治)的更多相关文章

  1. HDU-4742 Pinball Game 3D 三维LIS

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4742 题意:求3维的LIS.. 用分治算法搞得,参考了cxlove的题解.. 首先按照x排序,然后每个 ...

  2. hdu 4742 Pinball Game 3D(三维LIS&amp;cdq分治&amp;BIT维护最值)

    Pinball Game 3D Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  3. Luogu 3810 & BZOJ 3262 陌上花开/三维偏序 | CDQ分治

    Luogu 3810 & BZOJ 3263 陌上花开/三维偏序 | CDQ分治 题面 \(n\)个元素,每个元素有三个值:\(a_i\), \(b_i\) 和 \(c_i\).定义一个元素的 ...

  4. bzoj3262: 陌上花开 三维偏序cdq分治

    三维偏序裸题,cdq分治时,左侧的x一定比右侧x小,然后分别按y排序,对于左侧元素按y大小把z依次插入到树状数组里,其中维护每个左侧元素对右侧元素的贡献,在bit查询即可 /************* ...

  5. [bzoj] 3263 陌上花开 洛谷 P3810 三维偏序|| CDQ分治 && CDQ分治讲解

    原题 定义一个点比另一个点大为当且仅当这个点的三个值分别大于等于另一个点的三个值.每比一个点大就为加一等级,求每个等级的点的数量. 显然的三维偏序问题,CDQ的板子题. CDQ分治: CDQ分治是一种 ...

  6. BZOJ3262 陌上花开 —— 三维偏序 CDQ分治

    题目链接:https://vjudge.net/problem/HYSBZ-3262 3262: 陌上花开 Time Limit: 20 Sec  Memory Limit: 256 MBSubmit ...

  7. BZOJ 3295:[Cqoi2011]动态逆序对(三维偏序 CDQ分治+树状数组)

    http://www.lydsy.com/JudgeOnline/problem.php?id=3295 题意:简单明了. 思路:终于好像有点明白CDQ分治处理三维偏序了.把删除操作看作是插入操作,那 ...

  8. hdu4742 Pinball Game 3D

    真他娘的搞不懂cdq分治的顺序问题.但是candy?的博客里提到过,多想想吧-- #include <algorithm> #include <iostream> #inclu ...

  9. 三维偏序[cdq分治学习笔记]

    三维偏序 就是让第一维有序 然后归并+树状数组求两维 cdq+cdq不会 告辞 #include <bits/stdc++.h> // #define int long long #def ...

  10. cdq分治解决三维偏序

    问题背景 在三维坐标系中有n个点,坐标为(xi,yi,zi). 定义一个点A比一个点B小,当且仅当xA<=xB,yA<=yB,zA<=zB.问对于每个点,有多少个点比它小.(n< ...

随机推荐

  1. Android ProgressDialog 加载进度

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools= ...

  2. 使用CCUserDefault 推断用户是否是第一次登陆系统及UserDefault全路径的获取

    bool bfirst =CCUserDefault::sharedUserDefault()->getBoolForKey("first"); //假设不能获取该键值,创建 ...

  3. HDFS集群balance(4)-- 测试计划

    转载请注明博客地址:http://blog.csdn.net/suileisl HDFS集群balance,对应版本balance design 6 如需word版本,请QQ522173163联系索要 ...

  4. linux 声音大小调整的命令

    alsamixer 输入上面的命令 回车即可看到图形界面,界面如下 ┌──────────────────────────── AlsaMixer v1.0.27.1 ──────────────── ...

  5. 通过编写一个简单的漏洞扫描程序学习Python基本语句

    今天开始读<Python绝技:运用Python成为顶级黑客>一书,第一章用一个小例子来讲解Python的基本语法和语句.主要学习的内容有:1. 安装第三方库.2. 变量.字符串.列表.词典 ...

  6. 使用rpm安装mysql的默认目录

    --使用rpm安装mysql的默认目录:1.数据库目录/var/lib/mysql/2.配置文件/usr/share/mysql(mysql.server命令及配置文件)3.相关命令/usr/bin( ...

  7. MVC4建立DBContext的EF6数据

    MVC4建立DBContext的EF6数据时 1.需要using System.Data.Entity;命名空间 2.此命名空间需要安装EntityFromwork.dll,此dll可以在项目——&g ...

  8. 深入理解 CSS变形 transform(3d)

    坐标轴 在了解透视之前,首先要先了解坐标轴.3D变形与2D变形最大的不同就在于其参考的坐标轴不同.2D变形的坐标轴是平面的,只存在x轴和y轴,而3D变形的坐标轴则是x.y.z三条轴组成的立体空间,x轴 ...

  9. crontab 配置

    * * * * * (cd /opt/bd/www/crm/scripts/zb_insure; /opt/tuniu/php/bin/php /opt/bd/www/crm/scripts/zb_i ...

  10. Swift - 42 - 类的基本使用

    import Foundation /* 1.class表示类的关键字 2.class后面表示类名 3.类名后面的大括号内表示类的内部 */ /* 1.属性封装了set和get方法 2.方法里面封装了 ...