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

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

 #include <set>
#include <map>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const double eps = 1e-;
const int maxn = 1e5+;
const int mod = << ;
struct Ball
{
int x,y,z,idx;
bool operator < (const Ball &rhs)const
{
return x < rhs.x || (x == rhs.x && y < rhs.y) || (x == rhs.x && y == rhs.y && z < rhs.z);
}
} ball[maxn],tmpball[maxn];
struct DP
{
int len,cnt;
DP(){}
DP(int _len,int _cnt):
len(_len),cnt(_cnt) {}
} dp[maxn],c[maxn];
int vec[maxn],idx;
inline int lowbit (int x)
{
return x & -x;
}
inline void update (DP &dp1, DP &dp2)
{
if (dp1.len < dp2.len)
dp1 = dp2;
else if (dp1.len == dp2.len)
dp1.cnt += dp2.cnt;
}
inline void modify(int x,DP &d)
{
while (x <= idx)
{
update(c[x],d);
x += lowbit(x);
}
}
DP query(int x)
{
DP ans = DP (,);
while (x)
{
update(ans,c[x]);
x -= lowbit(x);
}
return ans;
}
inline void CLR(int x)
{
while (x <= idx)
{
c[x] = DP(,);
x += lowbit(x);
}
}
void CDQ (int l, int r)
{
if (l == r)
return ;
int mid = (l + r) >> ;
CDQ (l, mid);
for (int i = l; i <= r; i++)
{
tmpball[i] = ball[i];
tmpball[i].x = ;
}
sort(tmpball+l,tmpball+r+);
for (int i = l; i <= r; i++)
{
if (tmpball[i].idx <= mid)
{
modify(tmpball[i].z,dp[tmpball[i].idx]);
}
else
{
DP tmp = query(tmpball[i].z);
tmp.len++;
update(dp[tmpball[i].idx],tmp);
}
}
for (int i = l; i <= r; i++)
{
if (tmpball[i].idx <= mid)
{
CLR(tmpball[i].z);
}
}
CDQ (mid+, r);
}
int main(void)
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
#endif
int T, n;
scanf ("%d",&T);
while (T--)
{
scanf ("%d",&n);
for (int i = ; i <= n; i++)
{
scanf ("%d%d%d",&ball[i].x, &ball[i].y, &ball[i].z);
vec[i-] = ball[i].z;
}
sort (ball+, ball+n+);
sort (vec,vec+n);
idx = unique(vec,vec+n) - vec;
for (int i = ; i <= n ; i++)
{
ball[i].z = lower_bound(vec,vec+idx,ball[i].z) - vec + ;
ball[i].idx = i;
dp[i] = DP(,);
}
CDQ(,n);
DP ans = DP(,);
for (int i = ; i <= n ;i++)
{
update(ans,dp[i]);
}
printf("%d %d\n",ans.len, ans.cnt % mod);
}
return ;
}

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. [置顶] vb报表的设计

    敲机房收费系统,最难的部分应该就是关于报表的部分了.相对于学生信息管理系统,报表是新内容,在vb中添加报表需要添加第三方控件,首先我们要下载水晶报表,下面就向大家展示一下我设计报表的步骤(我用的新版本 ...

  2. App发布AppStore【苹果开发者中心需要做的事】

    请准许我的这句抱怨,也说明发布app到AppStore理清这些东西的重要性:起初打包出现各种 ApplicationVerificationFailed,不是这里没有搞对就是那个证书没有搞对,整个人签 ...

  3. 静态代码检查工具 cppcheck 的使用

      CppCheck是一个C/C++代码缺陷静态检查工具.不同于C/C++编译器及其它分析工具,CppCheck只检查编译器检查不出来的bug,不检查语法错误.所谓静态代码检查就是使用一个工具检查我们 ...

  4. Android 百度地图 SDK v3.0.0 (一)

    转载请标明出处:http://blog.csdn.net/lmj623565791/article/details/37729091 最近公司要把百度地图集成的项目中,于是我就研究了一天百度地图的SD ...

  5. java03变量和基本数据类型

    /** * * 失去一日甚易,欲得回已无途! * * 关键字:java中的关键字 就是指 已经被定义了的单词! * 我们就不能再拿关键字 作为我们的变量名! * 常用的关键字: * 基本数据类型: * ...

  6. 手机Web网站,设置拒绝电脑访问

    最近一段时间,都在使用Jquery-Mobile + MVC做手机Web,有一些心得.体会 下面介绍如何拒绝电脑访问手机网站 电脑的浏览器,跟手机的浏览器内核不一样,这是我设置拒绝访问的思路. 下面是 ...

  7. Entity Framework 新增实体,新增抽象实体

    抽象实体不能new 抽象类:人,实体类:学生 人 p_人= new 学生();   添加数据,学生和人都添加 抽象类可以提供一个抽象的方法,但是并没有实现,类似接口,但又不同于接口.子类继承父类时必须 ...

  8. mvvm框架正式名字确定

    经过长时间的选名,今天终于把名字定下来了,ddrjs  data drive render,其实框架的核心还是 数据驱动渲染,其实现在市面上的大部分mvvm框架如:angular.vue.avalon ...

  9. xAML中一些控件的用法学习

    首先,介绍一些比较简单的设计,这些可以直接通过拖拽实现.如下例子: <Window x:Class="wpf1.MainWindow" xmlns="http:// ...

  10. 武汉科技大学ACM :1003: A+B for Input-Output Practice (III)

    Problem Description Your task is to Calculate a + b. Input Input contains multiple test cases. Each ...