传送门

题解

看了半天完全没发现这东西和CDQ有什么关系……

先把原序列翻转,求起来方便

然后把每一个位置表示成$(a,b,c)$其中$a$表示位置,$b$表示高度,$c$表示速度,求有多少个位置$a,b,c$都小于它,这就是一个三维偏序问题,直接CDQ就可以解决了……

然后考虑如何求第二问,就是一个导弹所在的LIS数/总的LIS数,因为一个导弹的LIS必须包含自己,以$g[i]$表示以$i$结尾的LIS总数,不难发现有如下转移式

$$g[i]=\sum g[j] \{ (i<j,h[i]<h[j],v[i]<v[j],f[j]+1=f[i]\}$$

这个也可以用CDQ来解决,只要统计出之前最大的LIS再和$f$比较就好了(完全没想出来怎么会这么神仙……)

然后再求出以$i$为开头的LIS长度和方案数,两个相乘就是他自己的方案数了

代码好长……调了好久……

 //minamoto
#include<bits/stdc++.h>
using namespace std;
#define getc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
char buf[<<],*p1=buf,*p2=buf;
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,:;}
inline int read(){
#define num ch-'0'
char ch;bool flag=;int res;
while(!isdigit(ch=getc()))
(ch=='-')&&(flag=true);
for(res=num;isdigit(ch=getc());res=res*+num);
(flag)&&(res=-res);
#undef num
return res;
}
const int N=;
struct BIT{
int f;double w;
BIT(){f=,w=;}
BIT(int f,double w):f(f),w(w){}
}c[N];
int n,st[N],top=;
inline void add(int x,int f,double w){
for(int i=x;i<=n;i+=i&-i){
if(c[i].f<f){
if(c[i].f==) st[++top]=i;
c[i]=(BIT){f,w};
}
else if(c[i].f==f) c[i].w+=w;
}
}
inline BIT query(int x){
BIT res;
for(int i=x;i;i-=i&-i){
if(c[i].f>res.f) res=c[i];
else if(c[i].f==res.f) res.w+=c[i].w;
}
return res;
}
struct node{
int h,v,id,t;
int f[];double g[];
}a[N],q[N];
int wh[N],wv[N],id[N],rk[N];
inline bool cmp(int i,int j)
{return a[i].h<a[j].h||(a[i].h==a[j].h&&a[i].id<a[j].id);}
inline bool cmpid(const node &a,const node &b)
{return a.id<b.id;}
void solve(int l,int r,int t){
if(l==r){
if(a[l].f[t]<) a[l].f[t]=a[l].g[t]=;
return;
}
int mid=(l+r)>>;
memcpy(q+l,a+l,sizeof(node)*(r-l+));
int q1=l,q2=mid+;
for(int i=l;i<=r;++i){
q[i].t<=mid?a[q1++]=q[i]:a[q2++]=q[i];
}
solve(l,mid,t);
q1=l;
for(int i=mid+;i<=r;++i){
while(q1<=mid&&a[q1].id<a[i].id) add(a[q1].v,a[q1].f[t],a[q1].g[t]),++q1;
BIT res=query(a[i].v);
if(res.f==) continue;
if(res.f+>a[i].f[t]){
a[i].f[t]=res.f+,a[i].g[t]=res.w;
}
else if(res.f+==a[i].f[t]) a[i].g[t]+=res.w;
}
while(top){c[st[top--]]=(BIT){,};}
solve(mid+,r,t);
merge(a+l,a+mid+,a+mid+,a+r+,q+l,cmpid);
memcpy(a+l,q+l,sizeof(node)*(r-l+));
}
int th=,tv=;
int main(){
//freopen("testdata.in","r",stdin);
n=read();
for(int i=;i<=n;++i){
wh[i]=a[i].h=read(),wv[i]=a[i].v=read(),a[i].id=i,rk[i]=i;
}
sort(wh+,wh++n),sort(wv+,wv++n);
th=unique(wh+,wh++n)-wh-,tv=unique(wv+,wv++n)-wv-;
for(int i=;i<=n;++i){
a[i].h=th-(lower_bound(wh+,wh+th+,a[i].h)-wh)+;
a[i].v=tv-(lower_bound(wv+,wv+tv+,a[i].v)-wv)+;
}
sort(rk+,rk++n,cmp);
for(int i=;i<=n;++i) a[rk[i]].t=i;
solve(,n,);
for(int i=;i<=n;++i){
a[i].h=th-a[i].h+;
a[i].v=tv-a[i].v+;
a[i].id=n-a[i].id+;
a[i].t=n-a[i].t+;
}
reverse(a+,a++n);
solve(,n,);
reverse(a+,a++n);
double sum=;int ans=;
for(int i=;i<=n;++i){
int len=a[i].f[]+a[i].f[]-;
cmax(ans,len);
}
printf("%d\n",ans);
for(int i=;i<=n;++i){
if(a[i].f[]==ans) sum+=a[i].g[]*a[i].g[];
}
for(int i=;i<=n;++i){
double res=a[i].g[]*a[i].g[];
printf("%.5lf ",(a[i].f[]+a[i].f[]-==ans)?(res/sum):);
}
return ;
}

bzoj 2244 [SDOI2011]拦截导弹(dp+CDQ+树状数组)的更多相关文章

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

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

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

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

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

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

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

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

  5. BZOJ 1176/2683 Mokia (三维偏序CDQ+树状数组)

    题目大意: 洛谷传送门 三维偏序裸题.. 每次操作都看成一个三元组$<x,y,t>$,表示$x,y$坐标和操作时间$t $ 询问操作拆成$4$个容斥 接下来就是$CDQ$了,外层按t排序, ...

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

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

  7. BZOJ 2244 [SDOI2011]拦截导弹 (三维偏序CDQ+线段树)

    题目大意: 洛谷传送门 不愧为SDOI的duliu题 第一问?二元组的最长不上升子序列长度?裸的三维偏序问题,直接上$CDQ$ 由于是不上升,需要查询某一范围的最大值,并不是前缀最大值,建议用线段树实 ...

  8. BZOJ 2244 [SDOI2011]拦截导弹 ——CDQ分治

    三维偏序,直接CDQ硬上. 正反两次CDQ统计结尾的方案数,最后统计即可. #include <cstdio> #include <cstring> #include < ...

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

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

随机推荐

  1. 【334】Python Object-Oriented Programming

    Reference: Python中self用法详解 __init__ 方法: 私有变量. Reference: [290]Python 函数 class 里面的 function 创建与此一致,只是 ...

  2. 新手C#异常的学习2018.08.07

    异常是在程序执行期间出现的问题.C# 中的异常是对程序运行时出现的特殊情况的一种响应,比如尝试除以零. class Program { static void Main(string[] args) ...

  3. 使用Git将码云上的代码Clone至本地

    1. 安装Git https://git-scm.com/book/zh/v2/%E8%B5%B7%E6%AD%A5-%E5%AE%89%E8%A3%85-Git Git的网站上有详细的分各种系统的安 ...

  4. 13.Roman to Integer (HashTable)

    Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range from 1 t ...

  5. CF 990 Educational Codeforces Round 45

    既然补了就简单记录一下. 感觉还算有一点营养. 官方题解传送门:点我 A Commentary Boxes 对拆掉$n \mod m$个和新建$m - (n \mod m)$求个最小. #includ ...

  6. 分布式理论系列(三)ZAB 协议

    分布式理论系列(三)ZAB 协议 在学习了 Paxos 后,接下来学习 Paxos 在开源软件 Zookeeper 中的应用. 一.Zookeeper Zookeeper 致力于提供一个高性能.高可用 ...

  7. 8 种提升 ASP.NET Web API 性能的方法 (转)

    出处:http://www.oschina.net/translate/8-ways-improve-asp-net-web-api-performance ASP.NET Web API 是非常棒的 ...

  8. PowerDesigner工具建表步骤

    以商场VIP系统中的表为例 先建立管理员用户表 1.双击打开PowerDesigner工具,点File 选择 New Model  打开如下图,选择标红部分,点击OK 2点击选择标红部位Entity ...

  9. javascript 区分对象类型

    在 JavaScript 里使用 typeof 来判断数据类型,只能区分基本类型,即 “number”,”string”,”undefined”,”boolean”,”object” 五种.对于数组. ...

  10. 終于解決调用wordpress 4.3 xmlrpc api 发布包含分类的文章时返回“抱歉,文章类型不支持您的分类法”错误的問題

    這個問題我找了很多資料都沒有明說是如何解決,后來突發奇想得出我的解決方案如下,所以特此記錄一下: object postId = blogService.NewPost(0,"admin&q ...