BZOJ 2244 [SDOI2011]拦截导弹 ——CDQ分治
三维偏序,直接CDQ硬上。
正反两次CDQ统计结尾的方案数,最后统计即可。
- #include <cstdio>
- #include <cstring>
- #include <iostream>
- #include <algorithm>
- using namespace std;
- #define F(i,j,k) for (int i=j;i<=k;++i)
- #define D(i,j,k) for (int i=j;i>=i;--i)
- #define ll long double
- #define maxn 50005
- struct Mis{
- int id,h,v;
- void print()
- {
- printf("The ID %d High %d Speed %d\n",id,h,v);
- }
- }a[maxn];
- int f[maxn][2],n,h[maxn],v[maxn],htop,vtop;
- ll g[maxn][2];
- bool cmp1(Mis a,Mis b){return a.id<b.id;}
- bool cmp2(Mis a,Mis b){return a.h<b.h;}
- int mx[maxn]; ll cnt[maxn];
- void add(int x,int f,ll g)
- {
- for (;x<maxn;x+=x&(-x))
- if (mx[x]==f) cnt[x]+=g;
- else if (mx[x]<f) mx[x]=f,cnt[x]=g;
- else break;
- }
- int qmx(int x)
- {
- int ret=0;
- for (;x;x-=x&(-x)) ret=max(ret,mx[x]);
- return ret;
- }
- ll qcnt(int x,int m)
- {
- ll ret=0;
- for (;x;x-=x&(-x))
- if (mx[x]==m) ret+=cnt[x];
- return ret;
- }
- void del(int x)
- {
- for (;x<maxn;x+=x&(-x)) cnt[x]=mx[x]=0;
- }
- void CDQ(int l,int r,int flag)
- {
- if (l==r)
- {
- if (f[a[l].id][flag]<1)
- {
- g[a[l].id][flag]=f[a[l].id][flag]=1;
- }
- return ;
- }
- int mid=l+r>>1;
- sort(a+l,a+r+1,cmp1);
- CDQ(l,mid,flag);
- sort(a+l,a+mid+1,cmp2);
- sort(a+mid+1,a+r+1,cmp2);
- int pl=l;
- F(i,mid+1,r)
- {
- while (a[pl].h<=a[i].h&&pl<=mid) add(a[pl].v,f[a[pl].id][flag],g[a[pl].id][flag]),pl++;
- int tmp=qmx(a[i].v)+1;
- if (tmp==1) continue;
- if (tmp>f[a[i].id][flag])
- {
- f[a[i].id][flag]=tmp;
- g[a[i].id][flag]=qcnt(a[i].v,tmp-1);
- }
- else if (tmp==f[a[i].id][flag])
- g[a[i].id][flag]+=qcnt(a[i].v,tmp-1);
- }
- F(i,l,pl-1) del(a[i].v);
- CDQ(mid+1,r,flag);
- }
- void print()
- {
- int ans=0;
- F(i,1,n) ans=max(ans,f[i][0]);
- printf("%d\n",ans);
- ll sum=0;
- F(i,1,n) if (f[i][0]==ans) sum+=g[i][0]*g[n-i+1][1];
- F(i,1,n)
- {
- if (f[i][0]+f[n-i+1][1]-1==ans) printf("%.5Lf ",g[i][0]*g[n-i+1][1]/sum);
- else printf("0 ");
- }
- }
- int main()
- {
- scanf("%d",&n);htop=vtop=n;
- F(i,1,n)
- {
- scanf("%d%d",&a[i].h,&a[i].v);
- a[i].id=i;h[i]=a[i].h;v[i]=a[i].v;
- }
- sort(h+1,h+htop+1); sort(v+1,v+vtop+1);
- htop=unique(h+1,h+htop+1)-h-1; vtop=unique(v+1,v+vtop+1)-v-1;
- F(i,1,n)
- {
- a[i].h=lower_bound(h+1,h+htop+1,a[i].h)-h;
- a[i].v=lower_bound(v+1,v+vtop+1,a[i].v)-v;
- }
- F(i,1,n)
- {
- a[i].h=htop-a[i].h+1;
- a[i].v=vtop-a[i].v+1;
- }
- CDQ(1,n,0);
- F(i,1,n)
- {
- a[i].id=n-a[i].id+1;
- a[i].v=vtop-a[i].v+1;
- a[i].h=htop-a[i].h+1;
- }
- CDQ(1,n,1);
- print();
- }
BZOJ 2244 [SDOI2011]拦截导弹 ——CDQ分治的更多相关文章
- bzoj 2244: [SDOI2011]拦截导弹 cdq分治
2244: [SDOI2011]拦截导弹 Time Limit: 30 Sec Memory Limit: 512 MBSec Special JudgeSubmit: 237 Solved: ...
- BZOJ 2244: [SDOI2011]拦截导弹 (CDQ分治 三维偏序 DP)
题意 略- 分析 就是求最长不上升子序列,坐标取一下反就是求最长不下降子序列,比较大小是二维(h,v)(h,v)(h,v)的比较.我们不看概率,先看第一问怎么求最长不降子序列.设f[i]f[i]f[i ...
- BZOJ 2244: [SDOI2011]拦截导弹 [CDQ分治 树状数组]
传送门 题意:三维最长不上升子序列以及每个元素出现在最长不上升子序列的概率 $1A$了好开心 首先需要从左右各求一遍,长度就是$F[0][i]+F[1][i]-1$,次数就是$G[0][i]*G[1] ...
- BZOJ 2244: [SDOI2011]拦截导弹 DP+CDQ分治
2244: [SDOI2011]拦截导弹 Description 某国为了防御敌国的导弹袭击,发展出一种导弹拦截系统.但是这种导弹拦截系统有一个缺陷:虽然它的第一发炮弹能够到达任意的高度.并且能够拦截 ...
- [BZOJ2244][SDOI2011]拦截导弹 CDQ分治
2244: [SDOI2011]拦截导弹 Time Limit: 30 Sec Memory Limit: 512 MB Special Judge Description 某国为了防御敌国的导弹 ...
- bzoj 2244 [SDOI2011]拦截导弹(DP+CDQ分治+BIT)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=2244 [题意] 给定n个二元组,求出最长不上升子序列和各颗导弹被拦截的概率. [思路] ...
- BZOJ2244: [SDOI2011]拦截导弹(CDQ分治,二维LIS,计数)
Description 某国为了防御敌国的导弹袭击,发展出一种导弹拦截系统.但是这种导弹拦截系统有一个缺陷:虽然它的第一发炮弹能够到达任意的高度.并且能够拦截任意速度的导弹,但是以后每一发炮弹都不能高 ...
- bzoj 2244: [SDOI2011]拦截导弹
#include<cstdio> #include<iostream> #include<algorithm> #define M 100009 using nam ...
- bzoj 2244 [SDOI2011]拦截导弹(dp+CDQ+树状数组)
传送门 题解 看了半天完全没发现这东西和CDQ有什么关系…… 先把原序列翻转,求起来方便 然后把每一个位置表示成$(a,b,c)$其中$a$表示位置,$b$表示高度,$c$表示速度,求有多少个位置$a ...
随机推荐
- Windows系统下Android开发环境搭建
“工具善其事,必先利其器”.要想学好Android,搭建好Android开发环境是一个良好的开端. Windows系统下Android开发环境主要有4个大的步骤.分别是: 1.JDK的安装 2.ecl ...
- 你是猴子请来的逗比么!IT跳槽大事件
3月招聘大战早已硝烟四起,互联网职场摇身一变成了跳蚤市场,猎头们告诉跳蚤们,跳不跳不是不问题,往哪儿跳才是重点,跳对了高薪期权都如过眼云烟.不过小编不得不说,劳资最痛恨那些跳槽的人啦!就因为加班 ...
- PostgressSQL-Installation
安装 sudo apt install -y postgresql 自动生成一个名为 postgres 的 Linux 系统用户 $ finger postgres Login: postgres N ...
- lwz-过去一年的总结(15-16)
今天2016年2月6日,还有1个半小时的时间,就要离开这个工作了9个月的地方,准备前往下个城市了.趁着这点时间,来给过去的一年做个即兴的总结吧. 2015年的2月份,在以前同学的提议和支持下,我重新学 ...
- SpringAOP 设计原理
1. 设计原理 引入了,代理模式. java 程序执行流: 如果从虚拟机的角度看,整个程序的过程就是方法的调用,我们按照方法的执行顺序,将方法调用成一串. 在方法之间有着Join Point 连接点 ...
- Java——舞动的排序
一.冒泡排序: http://v.youku.com/v_show/id_XMzMyOTAyMzQ0.html //冒泡排序 public class Bubbling { public static ...
- shell脚本,通过传入的参数来计算最大值和最小值以及平均值。
[root@localhost zuoye]# cat quansges.sh #!/bin/bash > file [ ! $# -ge ] && || echo $* > ...
- javaEE(11)_事务处理
一.事务的概念 •事务指逻辑上的一组操作,组成这组操作的各个单元,要不全部成功,要不全部不成功. •例如:A——B转帐,对应于如下两条sql语句 update from account set mon ...
- Spring框架中的aop操作之一 及aspectjweaver.jar与aopalliance-1.0.jar下载地址 包含beans 注解context 和aop的约束
(aspect oriented programming面向切面编程) 首先在原有的jar包: 需Spring压缩包中的四个核心JAR包 beans .context.core 和expression ...
- Swift 编程思想 Part 4:map all the things!
Swift 编程思想 Part 4:map all the things! 2015-10-22 837 文章目录 1. 数组 vs. 可选类型 2. 作用在可选类型上的 map() 3. 回到我们 ...