1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
|
#include<bits/stdc++.h> using namespace std; #define Debug(x) cout<<#x<<':'<<x<<endl #define INF 0x7fffffff typedef long long ll; typedef pair<ll,ll> P; const ll maxn=1e5+11; struct Point{ ll x,y,w; bool operator < (const Point &b) const { if(y==b.y) return x>b.x; return y<b.y; } }p[maxn]; ll f[maxn],x[maxn]; ll n;
ll lowbit(ll x){return x & -x;}
void update(ll x,ll val){ for(;x<=n;f[x]=max(val,f[x]),x+=lowbit(x)); }
ll query(ll x){ ll ans=0; for(;x>=1;ans=max(ans,f[x]),x-=lowbit(x)); return ans; }
int main(){ ios::sync_with_stdio(false); cin.tie(0); ll ca;cin>>ca; while(ca--){ memset(f,0,sizeof(f)); cin>>n; for(ll i=1;i<=n;i++){ ll y,w;cin>>x[i]>>y>>w; p[i]={x[i],y,w}; } sort(p+1,p+n+1); sort(x+1,x+n+1); ll l=unique(x+1,x+n+1)-(x+1); for(ll i=1;i<=n;i++){ p[i].x=lower_bound(x+1,x+l+1,p[i].x)-x; } for(ll i=1;i<=n;i++){ ll uu=query(p[i].x-1)+p[i].w; update(p[i].x,uu); } cout<<query(l)<<endl; } return 0; }
|