题意:给定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. PAT 1043 输出PATest(20)(代码+思路)

    1043 输出PATest(20)(20 分) 给定一个长度不超过10000的.仅由英文字母构成的字符串.请将字符重新调整顺序,按"PATestPATest...."这样的顺序输出 ...

  2. Canvas绘图 (html5新增特性)

    Canvas 使用<canvas>对象,需要设置属性:width,height.指定绘图的区域大小.在canvas标签前后出现的信息将在不支持<canvas>元素的浏览器中显示 ...

  3. POJ3621或洛谷2868 [USACO07DEC]观光奶牛Sightseeing Cows

    一道\(0/1\)分数规划+负环 POJ原题链接 洛谷原题链接 显然是\(0/1\)分数规划问题. 二分答案,设二分值为\(mid\). 然后对二分进行判断,我们建立新图,没有点权,设当前有向边为\( ...

  4. DEDE 首页调用指定栏目链接的代码

    {dede:type typeid='6'} <a href='[field:typelink /]' target="_blank" >更多</a> {/ ...

  5. UI设计教程分享:字体变形—阴阳收缩法

    阴阳师中国古代对自然规律发展变化基础因素的描述,是古代美学逻辑思维.推理分析的核心要素,也是描述万物基本要素和成因的概念之一.阴阳代表事物的对立关系,它是自然界的客观规律,是万物运动变化的本源,是人类 ...

  6. How to make a USB stick use ISO image file in debian

    4.3.1. Preparing a USB stick using a hybrid CD or DVD image Debian CD and DVD images can now be writ ...

  7. [Robot Framework] 通过Robot Remote Server调用White Library测试WPF开发的桌面产品

    参考 : https://github.com/jatalahd/WhiteRobotLibrary 通过此源代码编译WhiteRobotLibrary.dll,然后把高亮标记的这5个dll全部拷贝到 ...

  8. AWVS基本用法

    https://www.bugbank.cn/q/article/5983de41cbb936102d397781.html

  9. 关键词提取_tf_idf

    TF-IDF(term frequency-inverse document frequency)-词频-逆文档频率 TF:统计一个词在文档中出现的频次,次数越多,表达能力越强 IDF:统计一个词在文 ...

  10. 虚函数与bind 实现设计模式的练习

    相同模式使用虚函数与bind function进行实现对比 #include "stdafx.h" #include <iostream> #include <f ...