题意:给定3维的n(<=100000)个点,求最长不下降子序列长度(对于1和2两个点,2可以放在1后面,x1<=x2,y1<=y2,z1<=z2 ),并求出有多少种方案。

思路:裸的cdq分治。。

首先可以先对x排序,就降成二维了。。

定义solve(l,r)为处理[l,r]的区间

那么solve(l,r)为如下:{

solve(l, mid)

对于l,r的点按照y关键字排序

然后从左到右(y增大方向)扫描,对于(l, mid)的点插入将值插入z离散化的数据结构里维护,

对于(mid+1,r)的点直接查询数据结果,更改结果

清空数据结构。

solve(mid+1, r)

}

大致就这样,可以做到nlog^2n的复杂度。。数据结构可以选用bit或者线段树。。不过大家都选用bit吧。。

cdq果然强大,还需慢慢体会呀。。

 /*
* Author: Yzcstc
* Created Time: 2014年10月03日 星期五 22时57分13秒
* File Name: hdu4742.cpp
*/
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <utility>
#define M0(x) memset(x, 0, sizeof(x))
#define MP make_pair
#define PB push_back
#define repf(i, a, b) for (int i = (a); i <= (b); ++i)
#define Inf 0x3fffffff
#define eps 1e-8
#define pi acos(-1)
#define maxn 120000
#define X first
#define Y second
using namespace std;
typedef pair<int, int> pii;
struct point{
int x, y, z,id;
void input(){
scanf("%d%d%d", &x, &y, &z);
}
bool operator<(const point& p) const{
if (x < p.x) return true;
if (x == p.x && y < p.y) return true;
if (x == p.x && y == p.y && z < p.z) return true;
return false;
}
} p[maxn], pt[maxn];
int t[maxn], n, m;
pii dp[maxn], v[maxn], zero(, ); void init(){
scanf("%d", &n);
for (int i = ; i <= n; ++i)
p[i].input(), t[i-] = p[i].z;
sort(p + , p + + n);
sort(t, t + n);
m = unique(t, t + n) - t;
// cout << m << endl;
for (int i = ; i <= n; ++i)
p[i].z = lower_bound(t, t + m, p[i].z) - t + ;
// repf(i, 1, n) printf("%d\n" ,p[i].z);
for (int i = ; i <= n; ++i)
p[i].id = i;
} /** BIT **/
inline int lowbit(const int& x){
return x & (-x);
} inline void update(pii &a, const pii &b){
if (a.X < b.X) a = b;
else if (a.X == b.X) a.Y += b.Y;
} void modify(int x, const pii& val){
for ( ; x <= m; x += lowbit(x))
update(v[x], val);
} pii query(int x){
pii ret(, );
for ( ; x > ; x -= lowbit(x))
update(ret, v[x]);
return ret;
} void recover(int x){
for (; x <= m; x += lowbit(x))
v[x] = zero;
}
/** BIT-end **/
/** Divide and conquer**/
pii tmp;
void solve(const int& l,const int& r){
if (l == r) return;
int mid = (l + r) >> ;
solve(l, mid);
int sz = ;
for (int i = l; i <= r; ++i)
pt[sz] = p[i], pt[sz++].x = ;
sort(pt, pt+sz);
for (int i = ; i < sz; ++i)
if (pt[i].id <= mid)
modify(pt[i].z, dp[pt[i].id]);
else
tmp = query(pt[i].z), ++tmp.X, update(dp[pt[i].id], tmp);
for (int i = ; i < sz; ++i)
if (pt[i].id <= mid)
recover(pt[i].z);
solve(mid + , r);
} void solve(){
for (int i = ; i <= n; ++i)
dp[i].X = dp[i].Y = ;
solve(, n);
pii ans(, );
for (int i = ; i <= n; ++i)
update(ans, dp[i]); // printf("i = %d: %d %d\n", i, dp[i].first, dp[i].second);
printf("%d %d\n", ans.X, ans.Y);
} int main(){
// freopen("a.in", "r", stdin);
// freopen("a.out", "w", stdout);
int cas;
scanf("%d", &cas);
while (cas--){
init();
solve();
}
return ;
}

hdu4742的更多相关文章

  1. HDU4742 CDQ分治,三维LIS

    HDU4742 CDQ分治,三维LIS 传送门:http://acm.hdu.edu.cn/showproblem.php?pid=4742 题意: 每个球都有三个属性值x,y,z,要求最长的lis的 ...

  2. HDU-4742 Pinball Game 3D 三维LIS

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4742 题意:求3维的LIS.. 用分治算法搞得,参考了cxlove的题解.. 首先按照x排序,然后每个 ...

  3. hdu4742 Pinball Game 3D

    真他娘的搞不懂cdq分治的顺序问题.但是candy?的博客里提到过,多想想吧-- #include <algorithm> #include <iostream> #inclu ...

  4. UvaLive 6667 Longest Chain (分治求三元组LIS&amp;树状数组)

    题目链接: here 题意: 和hdu4742类似.差别就是一部分三元组是直接给出的.另一部分是用他给的那个函数生成的.还有就是这里的大于是严格的大于a>b必须ax>bx,ay>by ...

  5. bryce1010专题训练——CDQ分治

    Bryce1010模板 CDQ分治 1.与普通分治的区别 普通分治中,每一个子问题只解决它本身(可以说是封闭的) 分治中,对于划分出来的两个子问题,前一个子问题用来解决后一个子问题而不是它本身 2.试 ...

  6. SPOJ Another Longest Increasing Subsequence Problem 三维最长链

    SPOJ Another Longest Increasing Subsequence Problem 传送门:https://www.spoj.com/problems/LIS2/en/ 题意: 给 ...

  7. UVA live 6667 三维严格LIS

    UVA live 6667 三维严格LIS 传送门:https://vjudge.net/problem/UVALive-6667 题意: 每个球都有三个属性值x,y,z,要求最长的严格lis的长度和 ...

随机推荐

  1. iOS.WWDC

    1. ASCIIwwdc: Searchable full-text transcripts of WWDC sessions http://asciiwwdc.com

  2. BZOJ1051或洛谷2341 [HAOI2006]受欢迎的牛

    BZOJ原题链接 洛谷原题链接 显然在一个强连通分量里的奶牛都可以相互喜欢,所以可以用\(tarjan\)求强连通并缩点. 要求明星奶牛必须被所有人喜欢,显然缩点后的图必须满足只有一个点没有出度,因为 ...

  3. 关于nodejs 假设httpserver,会发现一次网页打开,服务端会响应两次的问题;

    转自:http://cnodejs.org/topic/518772806d38277306804020 每个页面默认都会再发一个de style="line-height: 21px; p ...

  4. [Robot Framework] 搭建Robot Framework和RIDE(Robot Framework GUI) 的环境

    在windows x64的环境上进行安装,集成Selenium2和AutoIt的libraries,以下安装步骤在win 7,win 8.1,win 10, win 2012 R2上测试通过 1. 下 ...

  5. Python之路(第十八篇)shutil 模块、zipfile模块、configparser模块

    一.shutil 模块 1.shutil.copyfileobj(fsrc, fdst[, length]) 将文件内容拷贝到另一个文件中,需要打开文件 import shutil shutil.co ...

  6. python入门之文件处理

    1.读取文件 f=open(file="C:\BiZhi\新建文本文档.txt",mode="r",encoding="utf-8") da ...

  7. 数组方法splice

    删除功能: 语法:arrayObject.splice(index,count) 功能:删除从index处开始的零个或多个元素. 返回值:含有被删除的元素的数组 说明:count是要删除的项目数量,如 ...

  8. 34、iOS App图标和启动画面尺寸

    注意:iOS所有图标的圆角效果由系统生成,给到的图标本身不能是圆角的. 1. 桌面图标 (app icon) for iPhone6 plus(@3x) : 180 x 180 for iPhone ...

  9. 指令发布中如何实现new新消息的提醒?

    设计思路:反馈后,最急需了解反馈结果的是申请人,故给每一条反馈信息添加一个查看状态的字段,如CK_STATUS,并为这个状态设计为char(1)类型,java bean中使用integer可以实现默认 ...

  10. illustrator画梯形

    1.在空白文档上先绘制出一个长方形: 2.用鼠标点击工具箱中”自由变换“工具: 3.用鼠标指向长方形四个顶点中的任意一个,当鼠标的箭头变为相反反方向的双箭头时,再按住鼠标左键不要松手, 同时按住[sh ...