hdu4742
题意:给定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的更多相关文章
- HDU4742 CDQ分治,三维LIS
HDU4742 CDQ分治,三维LIS 传送门:http://acm.hdu.edu.cn/showproblem.php?pid=4742 题意: 每个球都有三个属性值x,y,z,要求最长的lis的 ...
- HDU-4742 Pinball Game 3D 三维LIS
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4742 题意:求3维的LIS.. 用分治算法搞得,参考了cxlove的题解.. 首先按照x排序,然后每个 ...
- hdu4742 Pinball Game 3D
真他娘的搞不懂cdq分治的顺序问题.但是candy?的博客里提到过,多想想吧-- #include <algorithm> #include <iostream> #inclu ...
- UvaLive 6667 Longest Chain (分治求三元组LIS&树状数组)
题目链接: here 题意: 和hdu4742类似.差别就是一部分三元组是直接给出的.另一部分是用他给的那个函数生成的.还有就是这里的大于是严格的大于a>b必须ax>bx,ay>by ...
- bryce1010专题训练——CDQ分治
Bryce1010模板 CDQ分治 1.与普通分治的区别 普通分治中,每一个子问题只解决它本身(可以说是封闭的) 分治中,对于划分出来的两个子问题,前一个子问题用来解决后一个子问题而不是它本身 2.试 ...
- SPOJ Another Longest Increasing Subsequence Problem 三维最长链
SPOJ Another Longest Increasing Subsequence Problem 传送门:https://www.spoj.com/problems/LIS2/en/ 题意: 给 ...
- UVA live 6667 三维严格LIS
UVA live 6667 三维严格LIS 传送门:https://vjudge.net/problem/UVALive-6667 题意: 每个球都有三个属性值x,y,z,要求最长的严格lis的长度和 ...
随机推荐
- 网页 PHP 动态师范
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- N! (大数,优化)
Problem Description 输出N的阶乘.(注意时间限制150ms&&注意不能打表后输出) 打表的定义:在本地主机预先计算出了每个值对应的答案,并把输入和输出的映射直接写入 ...
- 添加exe为windows service服务
[方法一] 一.介绍 srvany.exe是Microsoft Windows Resource Kits工具集的一个实用小工具,用于将EXE程序作为Windows服务运行.srvany是其注册程序的 ...
- LocalStorage的一些使用
LocalStorage是什么 LocalStorage 是在Html5中出现的一种本地存储.说到本地存储,大家立马会联想到Cookie,还有SqlLite. LocalStorage 中的数据不会像 ...
- 伪静态的服务器配置-如何php为 Discuz! X2 配置伪静态
URL 静态化是一个有利于搜索引擎的设置,通过 URL 静态化,达到原来是动态的 PHP 页面转换为静态化的 HTML 页面,可以提高搜索引擎抓取,当然,这里的静态化是一种假静态,目的只是提高搜索 ...
- Eclipse的下载及安装
Eclipse的下载地址: https://www.eclipse.org/downloads/ 下载完成后,双击安装包即可安装 选择 Eclipse IDE for Java EE Decelope ...
- ZVulDrill渗透环境搭建及部分题目writeup
一 实验环境 0x01 ZvulDirll 0x02 下载地址https://github.com/redBu1l/ZVulDrill 二 配置安装 0x01 在你网站的根目录下创建一个Vu ...
- ES线程池
每个Elasticsearch节点内部都维护着多个线程池,如index.search.get.bulk等,用户可以修改线程池的类型和大小,线程池默认大小跟CPU逻辑一致 一.查看当前线程组状态 cur ...
- iphone手机safari浏览器访问网站滚动条不显示问题解决办法
近排有公司同事出差在外需使用OA系统,发现iphone手机safari浏览器在该出现滚动条的页面没有显示滚动条,导致无法正常使用. 系统前端页面是采用jeasyui搭建的框架,使用iframe变更主页 ...
- spring boot 无法启动
spring boot 使用内置tomcat 报错 : Unable to start embedded Tomcat servlet container Tomcat connector in f ...