一眼看过去就x排序扫描一下,y是1e9的离散化一下,每层用树状数组维护一下,然后像dp倒着循环似的树状数组就用y倒着插就可行了。
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cctype>
#include <climits>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <sstream>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <fstream>
#include <bitset>
#define init(a, b) memset(a, b, sizeof(a))
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define irep(i, a, b) for (int i = a; i >= b; i--)
using namespace std; typedef double db;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
const int inf = 0x3f3f3f3f;
const ll INF = 1e18; template <typename T> void read(T &x) {
x = ;
int s = , c = getchar();
for (; !isdigit(c); c = getchar())
if (c == '-') s = -;
for (; isdigit(c); c = getchar())
x = x * + c - ;
x *= s;
} template <typename T> void write(T x) {
if (x < ) x = -x, putchar('-');
if (x > ) write(x / );
putchar(x % + '');
} template <typename T> void writeln(T x) {
write(x);
puts("");
} const int maxn = 1e5 + ;
int T, n;
struct cord {
int x, y, v; bool operator < (const cord& rhs) const {
if (x != rhs.x) return x < rhs.x;
return y > rhs.y;
}
}a[maxn];
int yy[maxn], tot;
struct BIT {
int F[maxn]; void Update(int pos, int val) {
for (; pos <= tot; pos += pos&-pos)
F[pos] = max(F[pos], val);
} int Query(int pos) {
int ret = ;
for (; pos; pos -= pos&-pos)
ret = max(ret, F[pos]);
return ret;
}
}bit; int main() {
for (read(T); T; T--, tot = ) {
read(n);
rep(i, , n) {
read(a[i].x);
read(a[i].y);
read(a[i].v);
yy[++tot] = a[i].y;
}
sort(yy + , yy + + tot);
tot = unique(yy + , yy + + tot) - yy - ;
rep(i, , n) {
a[i].y = lower_bound(yy + , yy + + tot, a[i].y) - yy;
} sort(a + , a + + n);
init(bit.F, );
rep(i, , n) {
bit.Update(a[i].y, bit.Query(a[i].y - ) + a[i].v);
}
writeln(bit.Query(tot));
}
return ;
}