TATT
题意:
求最长的非递减的四维偏序长度。
思路:
- 先将序列任选一个维度进行排序,然后依次将这些点插入到K-D Tree中。
- 每插入一个点之前,计算以当前点结尾的最长偏序长度(剩下的是三维偏序问题),然后再将当前点插入即可。
- 当然,K-D Tree重点还是在剪枝上。此处考虑两种剪枝即可:
- 如果当前子空间某一个维度的最下值都大于询问点的这一维度,则剪枝;
- 如果当前子空间最长偏序长度小于当前答案值,则剪枝(询问时优先处理可能的长度较长的子空间)。
代码
#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[