题意:现在有一个点堆, 一开始先给你m个点,然后再用题目中的rand函数生成剩下的n个点,问在这个点堆中可以找到的最长严格递增序列的长度是多少。

题解:

很常见的一个3维CDQ。

先按照z轴 sort 一遍,然后对于当前的序列去cdq分治。对于CDQ的每一层来说,都是用左边的点的值去更新右边点的值,对于每一层来说, 我们按照x轴sort, sort的时候注意,当同x的时候,一定是右边的询问点要在左边的修改点前面, 不然就不能保证前面的都是合法点, 对于每一个添加点来说,我们在其y轴对应的位置更新他的长度值, 对于每一个询问点来说, 我们在查询其y轴对应的位置的下面的地方去询问最长值。

但是题目中要求的是严格递增序列。

我们发现,会有中间的那一部分存在同z值的情况导致,中间偏左的点不能去更新中间偏右的点,但是我们可以发现,这个情况只会出现一个位置,对于每一次分治来说,那么我们开2个树状数组,去维护这个东西,一个梳妆数组存下左边的所有的更新点的值, 另一个梳妆数组维护 除去前面中间偏左不能维护中间偏右的那些点以外的值。

代码:

 #include<bits/stdc++.h>
using namespace std;
#define Fopen freopen("_in.txt","r",stdin); freopen("_out.txt","w",stdout);
#define LL long long
#define ULL unsigned LL
#define fi first
#define se second
#define pb push_back
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define lch(x) tr[x].son[0]
#define rch(x) tr[x].son[1]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
typedef pair<int,int> pll;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const LL mod = (int)1e9+;
const int N = 3e5 + ;
int ans[N];
int a, b, C = ~(<<), M = (<<)-;
int r(){
a = * (a & M) + (a >> );
b = * (b & M) + (b >> );
return (C&((a<<)+b)) % ;
}
struct Node{
int id, x, y, z;
}q[N], tmp[N];
bool cmp1(Node & n1, Node & n2){
return n1.z < n2.z;
}
bool cmp2(Node & n1, Node & n2){
if(n1.x != n2.x) return n1.x < n2.x;
return n1.id > n2.id;
}
int yyy[N];
int tree[][N];
void Add(int x, int val, int op){
for(int i = x; i < N; i+=i&(-i))
tree[op][i] = max(tree[op][i], val);
return ;
}
int query(int x, int op){
int ret = ;
for(int i = x; i > ; i -= i&(-i))
ret = max(tree[op][i], ret);
return ret;
}
void Clear(int x, int op){
for(int i = x; i < N; i+=i&(-i))
tree[op][i] = ;
return ;
}
void cdq(int l,int r){
if(l == r) {
ans[l] = max(ans[l], );
return ;
}
int m = l+r >> ;
cdq(l, m);
for(int i = l; i <= r; i++)
tmp[i] = q[i];
int midz = q[m+].z;
sort(tmp+l, tmp+r+, cmp2);
for(int i = l; i <= r; i++){
if(tmp[i].id <= m){
Add(tmp[i].y,ans[tmp[i].id],);
if(tmp[i].z != midz) Add(tmp[i].y,ans[tmp[i].id],);
}
else{
int val;
if(tmp[i].z != midz) val = query(tmp[i].y-, );
else val = query(tmp[i].y-,);
ans[tmp[i].id] = max(ans[tmp[i].id], val+);
}
}
for(int i = l; i <= r; i++){
if(tmp[i].id <= m){
Clear(tmp[i].y, );
if(tmp[i].z != midz) Clear(tmp[i].y,);
}
}
cdq(m+, r);
}
int main(){
int m, n, A, B;
while(~scanf("%d%d%d%d", &n, &m, &A, &B) && n+m+A+B){
a = A, b = B;
for(int i = ; i <= n; i++){
scanf("%d%d%d", &q[i].x, &q[i].y, &q[i].z);
yyy[i] = q[i].y;
}
for(int i = n+; i <= n+m; i++){
q[i].x = r(); q[i].y = r(); q[i].z = r();
yyy[i] = q[i].y;
}
sort(yyy+, yyy++n+m);
sort(q+, q++n+m, cmp1);
int ysz = unique(yyy+,yyy++n+m) - yyy - ;
for(int i = ; i <= n+m; i++){
q[i].id = i;
q[i].y = lower_bound(yyy+,yyy++ysz,q[i].y) - yyy;
ans[i] = ;
}
cdq(, n+m);
int fans = ;
for(int i = ; i <= n+m; i++)
fans = max(fans, ans[i]);
printf("%d\n", fans);
}
return ;
}

UVALive - 6667 Longest Chain CDQ3维问题的更多相关文章

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

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

  2. 2Sigma OA prepare: Longest Chain

    DP use HashMap: 根据string的长度sort,然后维护每个string的longest chain,default为1,如果删除某个char生成的string能提供更长的chain, ...

  3. UVALive - 7374 Racing Gems 二维非递减子序列

    题目链接: http://acm.hust.edu.cn/vjudge/problem/356795 Racing Gems Time Limit: 3000MS 问题描述 You are playi ...

  4. LeetCode 1048. Longest String Chain

    原题链接在这里:https://leetcode.com/problems/longest-string-chain/ 题目: Given a list of words, each word con ...

  5. (Problem 14)Longest Collatz sequence

    The following iterative sequence is defined for the set of positive integers: n n/2 (n is even) n 3n ...

  6. [LeetCode] Maximum Length of Pair Chain 链对的最大长度

    You are given n pairs of numbers. In every pair, the first number is always smaller than the second ...

  7. [Swift]LeetCode646. 最长数对链 | Maximum Length of Pair Chain

    You are given n pairs of numbers. In every pair, the first number is always smaller than the second ...

  8. 646. Maximum Length of Pair Chain(medium)

    You are given n pairs of numbers. In every pair, the first number is always smaller than the second ...

  9. 646. Maximum Length of Pair Chain 最长的链条长度

    [抄题]: You are given n pairs of numbers. In every pair, the first number is always smaller than the s ...

随机推荐

  1. UIRefreshControl 问题

    这两天在学UIRefreshControl,主要参照的是github上的一个Demo(网址 https://github.com/evgeniymikholap/UIRefreshControlExa ...

  2. 学习TensorFlow的第一天

    https://www.cnblogs.com/wangxiaocvpr/p/5902086.html

  3. Hyper-v设置linux固定ip

    一.创建CentOS 7专用的虚拟交换机 打开Hyper-v控制面板,找到右边的“虚拟交换机管理器” 进去后,点击“新建虚拟网络交换机”,填写名称后,选择“内部” 打开网络中心,修改配置如下图,注意i ...

  4. 有趣的RPC理解

    RPC(Remote Procedure Call)—远程过程调用,它是一种通过网络从远程计算机程序上请求服务,而不需要了解底层网络技术的协议.RPC协议假定某些传输协议的存在,如TCP或UDP,为通 ...

  5. 头部姿态估计 - Android

    概括 通过Dlib获得当前人脸的特征点,然后通过旋转平移标准模型的特征点进行拟合,计算标准模型求得的特征点与Dlib获得的特征点之间的差,使用Ceres不断迭代优化,最终得到最佳的旋转和平移参数. A ...

  6. eclipse解决properties文件中文乱码(两种方试)

    第一种:大多数网上搜到的情况(不靠谱) 第一步:windows-->properties-->General-->Content Types-->text(如下图) 第二步:p ...

  7. js学习之数据类型

    js学习之数据类型 基础类型:number string boolean null undefined 引用类型:object array function undefined值是派生自null值的( ...

  8. laravel新项目报错 No application encryption key has been specified.

    解决办法, 若文件根目录下没有 .env 1..env.example 改名使用命令 copy 修改为 .env 2.使用命令 php artisan key:generate  获取密码,自动保存到 ...

  9. Win服务程序编写以及安装一般步骤

    Win服务程序编写以及安装一般步骤 Windows服务的优点有:1. 能够自动运行.2. 不要求用户交互.3. 在后台运行.本文将介绍常见服务程序编写的一般步骤以及注意事项. 设计服务程序实例: 创建 ...

  10. pythonday02基础与运算符

    今日概要 1.循环 2.字符串格式化 3.运算符 4.编码 if的嵌套 score = input('请输入成绩') score_int = int(score) if score_int >= ...