bit扫描坐标套路题,注意有重复的点,莽WA了。
const int maxn = 1e5 + 5;
struct node {
ll B, F, D;
bool operator < (const node &rhs) const {
if (B != rhs.B) return B > rhs.B;
return F < rhs.F;
}
}a[maxn];
int n, tot;
ll c[maxn], ans;
struct BIT {
ll t[maxn];
void Modify(int x, ll val) {
for (; x; x -= x&-x)
t[x] = max(t[x], val);
}
ll Query(int x) {
ll ret = 0;
for (; x <= tot; x += x&-x)
ret = max(t[x], ret);
return ret;
}
}T;
int main() {
read(n);
rep(i, 1, n) {
read(a[i].B);
read(a[i].F);
read(a[i].D);
c[++tot] = a[i].F;
}
sort(c + 1, c + tot + 1);
tot = unique(c + 1, c + 1 + tot) - c - 1;
rep(i, 1, n) {
a[i].F = lower_bound(c + 1, c + 1 + tot, a[i].F) - c;
}
sort(a + 1, a + 1 + n);
ll tmp = 0;
rep(i, 1, n) {
if (a[i].B == a[i - 1].B && a[i].F == a[i - 1].F)
tmp += a[i].D;
else tmp = T.Query(a[i].F + 1) + a[i].D;
ans = max(ans, tmp);
T.Modify(a[i].F, tmp);
}
writeln(ans);
return 0;
}