三维偏序,直接CDQ硬上。

正反两次CDQ统计结尾的方案数,最后统计即可。

  1. #include <cstdio>
  2. #include <cstring>
  3. #include <iostream>
  4. #include <algorithm>
  5. using namespace std;
  6. #define F(i,j,k) for (int i=j;i<=k;++i)
  7. #define D(i,j,k) for (int i=j;i>=i;--i)
  8. #define ll long double
  9. #define maxn 50005
  10. struct Mis{
  11. int id,h,v;
  12. void print()
  13. {
  14. printf("The ID %d High %d Speed %d\n",id,h,v);
  15. }
  16. }a[maxn];
  17. int f[maxn][2],n,h[maxn],v[maxn],htop,vtop;
  18. ll g[maxn][2];
  19. bool cmp1(Mis a,Mis b){return a.id<b.id;}
  20. bool cmp2(Mis a,Mis b){return a.h<b.h;}
  21. int mx[maxn]; ll cnt[maxn];
  22. void add(int x,int f,ll g)
  23. {
  24. for (;x<maxn;x+=x&(-x))
  25. if (mx[x]==f) cnt[x]+=g;
  26. else if (mx[x]<f) mx[x]=f,cnt[x]=g;
  27. else break;
  28. }
  29. int qmx(int x)
  30. {
  31. int ret=0;
  32. for (;x;x-=x&(-x)) ret=max(ret,mx[x]);
  33. return ret;
  34. }
  35. ll qcnt(int x,int m)
  36. {
  37. ll ret=0;
  38. for (;x;x-=x&(-x))
  39. if (mx[x]==m) ret+=cnt[x];
  40. return ret;
  41. }
  42. void del(int x)
  43. {
  44. for (;x<maxn;x+=x&(-x)) cnt[x]=mx[x]=0;
  45. }
  46. void CDQ(int l,int r,int flag)
  47. {
  48. if (l==r)
  49. {
  50. if (f[a[l].id][flag]<1)
  51. {
  52. g[a[l].id][flag]=f[a[l].id][flag]=1;
  53. }
  54. return ;
  55. }
  56. int mid=l+r>>1;
  57. sort(a+l,a+r+1,cmp1);
  58. CDQ(l,mid,flag);
  59. sort(a+l,a+mid+1,cmp2);
  60. sort(a+mid+1,a+r+1,cmp2);
  61. int pl=l;
  62. F(i,mid+1,r)
  63. {
  64. while (a[pl].h<=a[i].h&&pl<=mid) add(a[pl].v,f[a[pl].id][flag],g[a[pl].id][flag]),pl++;
  65. int tmp=qmx(a[i].v)+1;
  66. if (tmp==1) continue;
  67. if (tmp>f[a[i].id][flag])
  68. {
  69. f[a[i].id][flag]=tmp;
  70. g[a[i].id][flag]=qcnt(a[i].v,tmp-1);
  71. }
  72. else if (tmp==f[a[i].id][flag])
  73. g[a[i].id][flag]+=qcnt(a[i].v,tmp-1);
  74. }
  75. F(i,l,pl-1) del(a[i].v);
  76. CDQ(mid+1,r,flag);
  77. }
  78. void print()
  79. {
  80. int ans=0;
  81. F(i,1,n) ans=max(ans,f[i][0]);
  82. printf("%d\n",ans);
  83. ll sum=0;
  84. F(i,1,n) if (f[i][0]==ans) sum+=g[i][0]*g[n-i+1][1];
  85. F(i,1,n)
  86. {
  87. if (f[i][0]+f[n-i+1][1]-1==ans) printf("%.5Lf ",g[i][0]*g[n-i+1][1]/sum);
  88. else printf("0 ");
  89. }
  90. }
  91. int main()
  92. {
  93. scanf("%d",&n);htop=vtop=n;
  94. F(i,1,n)
  95. {
  96. scanf("%d%d",&a[i].h,&a[i].v);
  97. a[i].id=i;h[i]=a[i].h;v[i]=a[i].v;
  98. }
  99. sort(h+1,h+htop+1); sort(v+1,v+vtop+1);
  100. htop=unique(h+1,h+htop+1)-h-1; vtop=unique(v+1,v+vtop+1)-v-1;
  101. F(i,1,n)
  102. {
  103. a[i].h=lower_bound(h+1,h+htop+1,a[i].h)-h;
  104. a[i].v=lower_bound(v+1,v+vtop+1,a[i].v)-v;
  105. }
  106. F(i,1,n)
  107. {
  108. a[i].h=htop-a[i].h+1;
  109. a[i].v=vtop-a[i].v+1;
  110. }
  111. CDQ(1,n,0);
  112. F(i,1,n)
  113. {
  114. a[i].id=n-a[i].id+1;
  115. a[i].v=vtop-a[i].v+1;
  116. a[i].h=htop-a[i].h+1;
  117. }
  118. CDQ(1,n,1);
  119. print();
  120. }

  

BZOJ 2244 [SDOI2011]拦截导弹 ——CDQ分治的更多相关文章

  1. bzoj 2244: [SDOI2011]拦截导弹 cdq分治

    2244: [SDOI2011]拦截导弹 Time Limit: 30 Sec  Memory Limit: 512 MBSec  Special JudgeSubmit: 237  Solved: ...

  2. BZOJ 2244: [SDOI2011]拦截导弹 (CDQ分治 三维偏序 DP)

    题意 略- 分析 就是求最长不上升子序列,坐标取一下反就是求最长不下降子序列,比较大小是二维(h,v)(h,v)(h,v)的比较.我们不看概率,先看第一问怎么求最长不降子序列.设f[i]f[i]f[i ...

  3. BZOJ 2244: [SDOI2011]拦截导弹 [CDQ分治 树状数组]

    传送门 题意:三维最长不上升子序列以及每个元素出现在最长不上升子序列的概率 $1A$了好开心 首先需要从左右各求一遍,长度就是$F[0][i]+F[1][i]-1$,次数就是$G[0][i]*G[1] ...

  4. BZOJ 2244: [SDOI2011]拦截导弹 DP+CDQ分治

    2244: [SDOI2011]拦截导弹 Description 某国为了防御敌国的导弹袭击,发展出一种导弹拦截系统.但是这种导弹拦截系统有一个缺陷:虽然它的第一发炮弹能够到达任意的高度.并且能够拦截 ...

  5. [BZOJ2244][SDOI2011]拦截导弹 CDQ分治

    2244: [SDOI2011]拦截导弹 Time Limit: 30 Sec  Memory Limit: 512 MB  Special Judge Description 某国为了防御敌国的导弹 ...

  6. bzoj 2244 [SDOI2011]拦截导弹(DP+CDQ分治+BIT)

    [题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=2244 [题意] 给定n个二元组,求出最长不上升子序列和各颗导弹被拦截的概率. [思路] ...

  7. BZOJ2244: [SDOI2011]拦截导弹(CDQ分治,二维LIS,计数)

    Description 某国为了防御敌国的导弹袭击,发展出一种导弹拦截系统.但是这种导弹拦截系统有一个缺陷:虽然它的第一发炮弹能够到达任意的高度.并且能够拦截任意速度的导弹,但是以后每一发炮弹都不能高 ...

  8. bzoj 2244: [SDOI2011]拦截导弹

    #include<cstdio> #include<iostream> #include<algorithm> #define M 100009 using nam ...

  9. bzoj 2244 [SDOI2011]拦截导弹(dp+CDQ+树状数组)

    传送门 题解 看了半天完全没发现这东西和CDQ有什么关系…… 先把原序列翻转,求起来方便 然后把每一个位置表示成$(a,b,c)$其中$a$表示位置,$b$表示高度,$c$表示速度,求有多少个位置$a ...

随机推荐

  1. Windows系统下Android开发环境搭建

    “工具善其事,必先利其器”.要想学好Android,搭建好Android开发环境是一个良好的开端. Windows系统下Android开发环境主要有4个大的步骤.分别是: 1.JDK的安装 2.ecl ...

  2. 你是猴子请来的逗比么!IT跳槽大事件

       3月招聘大战早已硝烟四起,互联网职场摇身一变成了跳蚤市场,猎头们告诉跳蚤们,跳不跳不是不问题,往哪儿跳才是重点,跳对了高薪期权都如过眼云烟.不过小编不得不说,劳资最痛恨那些跳槽的人啦!就因为加班 ...

  3. PostgressSQL-Installation

    安装 sudo apt install -y postgresql 自动生成一个名为 postgres 的 Linux 系统用户 $ finger postgres Login: postgres N ...

  4. lwz-过去一年的总结(15-16)

    今天2016年2月6日,还有1个半小时的时间,就要离开这个工作了9个月的地方,准备前往下个城市了.趁着这点时间,来给过去的一年做个即兴的总结吧. 2015年的2月份,在以前同学的提议和支持下,我重新学 ...

  5. SpringAOP 设计原理

    1.  设计原理 引入了,代理模式. java 程序执行流: 如果从虚拟机的角度看,整个程序的过程就是方法的调用,我们按照方法的执行顺序,将方法调用成一串. 在方法之间有着Join Point 连接点 ...

  6. Java——舞动的排序

    一.冒泡排序: http://v.youku.com/v_show/id_XMzMyOTAyMzQ0.html //冒泡排序 public class Bubbling { public static ...

  7. shell脚本,通过传入的参数来计算最大值和最小值以及平均值。

    [root@localhost zuoye]# cat quansges.sh #!/bin/bash > file [ ! $# -ge ] && || echo $* > ...

  8. javaEE(11)_事务处理

    一.事务的概念 •事务指逻辑上的一组操作,组成这组操作的各个单元,要不全部成功,要不全部不成功. •例如:A——B转帐,对应于如下两条sql语句 update from account set mon ...

  9. Spring框架中的aop操作之一 及aspectjweaver.jar与aopalliance-1.0.jar下载地址 包含beans 注解context 和aop的约束

    (aspect oriented programming面向切面编程) 首先在原有的jar包: 需Spring压缩包中的四个核心JAR包 beans .context.core 和expression ...

  10. Swift 编程思想 Part 4:map all the things!

    Swift 编程思想 Part 4:map all the things! 2015-10-22  837 文章目录 1. 数组 vs. 可选类型 2. 作用在可选类型上的 map() 3. 回到我们 ...