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的长度和 ...
随机推荐
- Introduction to 3D Game Programming with DirectX 11 翻译--开篇
Direct3D 11简介 Direct3D 11是一个渲染库,用于在Windows平台上使用现代图形硬件编写高性能3D图形应用程序.Direct3D是一个windows底层库,因为它的应用程序编程接 ...
- widget jquery 理解
jquery ui 的所有组件都是基于一个简单,可重用的widget. 这个widget是jquery ui的核心部分,实用它能实现一致的API,创建有状态的插件,而无需关心插件的内部转换. $.wi ...
- 使用VNC连接管理VPS
本文基于:Kvm+Windows2008 VPS+VNCviewer 有时候遇上IP没设置好,IP被封,调整磁盘,重置windows系统密码等等使用基于VNC的控制台对VPS进行操作是非常方便的. 有 ...
- Android Studio 小新兵
1. java.lang.IllegalStateException: This app has been built with an incorrect configuration. Please ...
- 字符串匹配 - sunday算法
常见的字符串匹配算法有BF.KMP(教科书中非常经典的).BM.Sunday算法 这里主要想介绍下性能比较好并且实现比较简单的Sunday算法 . 基本原理: 从前往后匹配,如果遇到不匹配情况判断母串 ...
- js 光标位置处理
/** * 获取选中文字 * 返回selection,toString可拿到结果,selection含有起始光标位置信息等 **/ function getSelectText() { var tex ...
- vue ui之 iview 事件拦截
用过easyui的,应该清楚easyui组件有很多before事件拦截,有时候会特别重要. 最近在研究vue的ui组件iview虽然功能也不错,感觉还是没有像easyui那样强大,就比如before事 ...
- Spring配置ArgumentResolver,统一进行session鉴定
一.编写WebMvcConfig配置类: 重写addArgumentResolvers方法,将解析类加入 @Configuration public class WebConfig extends W ...
- unity在一个对象上挂多个一样的脚本怎么获取
使用GetComponents获取,存到一个该类的数组里
- 48.UIButton上的字体居右对齐
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom]; button.titleLabel.textAlignment = NSTe ...