Problem Description
RD is a smart boy and excel in pinball game. However, playing common 2D pinball game for a great number of times results in accumulating tedium. 
Recently, RD has found a new type of pinball game, a 3D pinball game. The 3D pinball game space can be regarded as a three dimensional coordinate system containing N balls. A ball can be considered as a point. At the beginning, RD made a shot and hit a ball. The ball hit by RD will move and may hit another ball and the “another ball” may move and hit another another ball, etc. But once a ball hit another ball, it will disappear.
RD is skilled in this kind of game, so he is able to control every ball's moving direction. But there is a limitation: if ball A's coordinate is (x1,y1,z1) and ball B's coordinate is (x2,y2,z2), then A can hit B only if x1 <= x2 and y1 <= y2 and z1 <= z2.
Now, you should help RD to calculate the maximum number of balls that can be hit and the number of different shooting schemes that can achieve that number. Two schemes are different if the sets of hit balls are not the same. The order doesn't matter.
 
Input
The first line contains one integer T indicating the number of cases. In each case, the first line contains one integer N indicating the number of balls.  The next N lines each contains three non-negative integer (x, y, z), indicating the coordinate of a ball.  The data satisfies T <= 3, N <= 105, 0 <= x, y, z <= 230, no two balls have the same coordinate in one case.
 
Output
Print two integers for each case in a line, indicating the maximum number of balls that can be hit and the number of different shooting schemes. As the number of schemes can be quite large, you should output this number mod 230.
 
Sample Input
2
3
2 0 0
0 1 0
0 1 1
5
3 0 0
0 1 0
0 0 1
0 2 2
3 3 3
 
Sample Output
2 1
3 2

题意: 求满足最大的上升序列长度和个数,对于一个三元组(x,y,z) 要求x1<=x2,y1<=y2,z1<=z2

解析: CDQ处理,先把z值离散化,再把所有的三元组按照(x,y,z)排好序,CDQ分治处理 CDQ思想:对于区间[l,r],先递归处理左半区间[l,mid](左边的信息已经更新好了), 再处理当前区间,用前mid个元素更新后半部分的值,一般是插入到某种数据结构中, 后半部分通过查询更新值,最后处理右半区间[mid+1,r],相当于从左到右处理完所有 的元素。具体实现见代码。

代码

  1. #include<cstdio>
  2. #include<cstring>
  3. #include<string>
  4. #include<algorithm>
  5. using namespace std;
  6. #define fi first
  7. #define se second
  8. typedef pair<int,int> par;
  9. const int maxn=;
  10. int N,ms,A[maxn];//A用于离散化z值
  11. par dp[maxn],tree[maxn],zero(,); //dp的fi保存长度,se保存大小,tree用于树状数组
  12. struct node
  13. {
  14. int x,y,z,id;
  15. node(int x=,int y=,int z=):x(x),y(y),z(z){}
  16. bool operator < (const node& t) const //依次排x,y,z
  17. {
  18. if(x!=t.x) return x<t.x;
  19. if(y!=t.y) return y<t.y;
  20. return z<t.z;
  21. }
  22. }nod[maxn],tnod[maxn];
  23.  
  24. void init()
  25. {
  26. scanf("%d",&N);
  27. int x,y,z;
  28. for(int i=;i<N;i++)
  29. {
  30. scanf("%d%d%d",&x,&y,&z);
  31. nod[i]=node(x,y,z);
  32. A[i]=z;
  33. }
  34. sort(nod,nod+N);
  35. sort(A,A+N);
  36. ms=;
  37. for(int i=;i<N;i++) if(A[ms]!=A[i]) A[++ms]=A[i];
  38. for(int i=;i<N;i++)
  39. {
  40. nod[i].z=lower_bound(A,A+ms+,nod[i].z)-A+;
  41. nod[i].id=i;
  42. }
  43. }
  44. int lowbit(int x){ return x&(-x); }
  45. void Update(par& a,const par& b) //更新
  46. {
  47. if(a.fi<b.fi) a=b; //长度小
  48. else if(a.fi==b.fi) a.se+=b.se; //加上这么多种情况
  49. }
  50. void Modify(int i,const par& b){ for(;i<=ms;i+=lowbit(i)) Update(tree[i],b); }
  51. par Query(int i)
  52. {
  53. par ret=zero;
  54. for(;i>;i-=lowbit(i)) Update(ret,tree[i]);
  55. return ret;
  56. }
  57. void Recover(int i){ for(;i<=ms;i+=lowbit(i)) tree[i]=zero; }
  58. void CDQ(int l,int r)
  59. {
  60. if(l==r) return;
  61. if(l>r) return;
  62. int mid=(l+r)/;
  63. CDQ(l,mid);//先处理左边边
  64. int k=;
  65. for(int i=l;i<=r;i++) { tnod[k]=nod[i]; tnod[k++].x=; }
  66. sort(tnod,tnod+k);
  67. for(int i=;i<k;i++)
  68. {
  69. node& t=tnod[i];
  70. if(t.id<=mid) Modify(t.z,dp[t.id]); //左边已经处理过,只需要插入即可
  71. else // 更新右边
  72. {
  73. par a=Query(t.z);
  74. a.fi++;
  75. Update(dp[t.id],a);
  76. }
  77. }
  78. for(int i=;i<k;i++) //一定要恢复,不然会影响后面的
  79. {
  80. node& t=tnod[i];
  81. if(t.id<=mid) Recover(t.z);
  82. }
  83. CDQ(mid+,r); //再处理右边
  84. }
  85. int main()
  86. {
  87. int T;
  88. scanf("%d",&T);
  89. while(T--)
  90. {
  91. init();
  92. for(int i=;i<N;i++) dp[i].fi=dp[i].se=;
  93. CDQ(,N-);
  94. par ans=zero;
  95. for(int i=;i<N;i++) Update(ans,dp[i]);
  96. printf("%d %d\n",ans.fi,ans.se);
  97. }
  98. return ;
  99. }

Hdu4742-Pinball Game 3D(cdq分治+树状数组)的更多相关文章

  1. HDU 4247 Pinball Game 3D(cdq 分治+树状数组+动态规划)

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

  2. hdu_4742_Pinball Game 3D(cdq分治+树状数组)

    题目链接:hdu_4742_Pinball Game 3D 题意: 给你n个点,让你求三维的LIS,并且求出有多少种组合能达到LIS. 题解: 求三维的LIS,典型的三维偏序问题,x排序,解决一维,c ...

  3. 【BZOJ4553】[Tjoi2016&Heoi2016]序列 cdq分治+树状数组

    [BZOJ4553][Tjoi2016&Heoi2016]序列 Description 佳媛姐姐过生日的时候,她的小伙伴从某宝上买了一个有趣的玩具送给他.玩具上有一个数列,数列中某些项的值可能 ...

  4. BZOJ 1176 Mokia CDQ分治+树状数组

    1176: [Balkan2007]Mokia Time Limit: 30 Sec  Memory Limit: 162 MBSubmit: 1854  Solved: 821[Submit][St ...

  5. 【bzoj3262】陌上花开 CDQ分治+树状数组

    题目描述 有n朵花,每朵花有三个属性:花形(s).颜色(c).气味(m),又三个整数表示.现要对每朵花评级,一朵花的级别是它拥有的美丽能超过的花的数量.定义一朵花A比另一朵花B要美丽,当且仅当Sa&g ...

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

  7. BZOJ 2683 简单题 cdq分治+树状数组

    题意:链接 **方法:**cdq分治+树状数组 解析: 首先对于这道题,看了范围之后.二维的数据结构是显然不能过的.于是我们可能会考虑把一维排序之后还有一位上数据结构什么的,然而cdq分治却可以非常好 ...

  8. LOJ3146 APIO2019路灯(cdq分治+树状数组)

    每个时刻都形成若干段满足段内任意两点可达.将其视为若干正方形.则查询相当于求历史上某点被正方形包含的时刻数量.并且注意到每个时刻只有O(1)个正方形出现或消失,那么求出每个矩形的出现时间和消失时间,就 ...

  9. BZOJ 4553 [Tjoi2016&Heoi2016]序列 ——CDQ分治 树状数组

    考虑答案的构成,发现是一个有限制条件的偏序问题. 然后三个维度的DP,可以排序.CDQ.树状数组各解决一维. #include <map> #include <cmath> # ...

随机推荐

  1. hdu1796:容斥入门题

    简单的容斥入门题.. 容斥基本的公式早就知道了,但是一直不会写. 下午看到艾神在群里说的“会枚举二进制数就会容斥”,后来发现还真是这样.. 然后直接贴代码了 #include <iostream ...

  2. Hybrid App开发模式中, IOS/Android 和 JavaScript相互调用方式

    IOS:Objective-C 和 JavaScript 的相互调用 iOS7以前,iOS SDK 并没有原生提供 js 调用 native 代码的 API.但是 UIWebView 的一个 dele ...

  3. [RxJS] Sharing Streams with Share

    A stream will run with each new subscription added to it. This lesson shows the benefits of using sh ...

  4. 操作系统下查看HBA卡信息wwn的方法

    一.Windows 系统在Windows系统中,可以使用FC HBA卡厂家提供的管理软件查看光纤适配器的WWN号码,具体如下:Qlogic:SANsurferEmulex:HBAnyware http ...

  5. Memory Analyzer Blog

    引用:http://memoryanalyzer.blogspot.jp/2008/05/automated-heap-dump-analysis-finding.html Dienstag, 27. ...

  6. 深入javascript——构造函数和原型对象

    常用的几种对象创建模式 使用new关键字创建 最基础的对象创建方式,无非就是和其他多数语言一样说的一样:没对象,你new一个呀! var gf = new Object(); gf.name = &q ...

  7. 16 Socket通信(简单例子)

      服务端代码: import java.io.*; import java.net.ServerSocket; import java.net.Socket; import java.util.Da ...

  8. JedisPool操作

    Jedis 使用 commons-pool 完成池化实现. 先做个配置文件(properties文件): #最大分配的对象数 redis.pool.maxActive=1024 #最大能够保持idel ...

  9. VC连接数据库方式

    转自:http://www.cnblogs.com/renyuan/archive/2012/07/27/2612412.html 目前Windows系统上常见的数据库接口包括: ODBC(开放数据库 ...

  10. phpwind 去除init.phpwind.net统计功能

    修改的文件如下:global.phplib/staticpage.class.phprequire/template.phpsimple/index.php