TATT(K-D Tree + 四维偏序)

TATT

题意:

求最长的非递减的四维偏序长度。

思路:

  1. 先将序列任选一个维度进行排序,然后依次将这些点插入到K-D Tree中。
  2. 每插入一个点之前,计算以当前点结尾的最长偏序长度(剩下的是三维偏序问题),然后再将当前点插入即可。
  3. 当然,K-D Tree重点还是在剪枝上。此处考虑两种剪枝即可:
    1. 如果当前子空间某一个维度的最下值都大于询问点的这一维度,则剪枝;
    2. 如果当前子空间最长偏序长度小于当前答案值,则剪枝(询问时优先处理可能的长度较长的子空间)。

代码

#include "bits/stdc++.h"
#define hhh printf("hhh\n")
#define see(x) (cerr<<(#x)<<'='<<(x)<<endl)
using namespace std;
typedef long long ll;
typedef pair<int,int> pr;
inline int read() {
   int x=0,f=1;char c=getchar();while(c!='-'&&(c<'0'||c>'9'))c=getchar();if(c=='-')f=-1,c=getchar();while(c>='0'&&c<='9')x=x*10+c-'0',c=getchar();return f*x;}

const int maxn = 5e4+10;
const int inf = 0x3f3f3f3f;
const int mod = 1e9+7;
const double eps = 1e-7;

int n, Dim, tot, rt, top;
int ls[maxn], rs[maxn], sz[maxn], mi[maxn][3], mx[maxn], rub[maxn];

struct P{
   
    int x[4], f;
    friend bool operator < (const P &a, const P &b) {
   
        for(int i=3; i>=0; --i) {
   
            if(a.x[
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值