Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- #define gc c=getchar()
- #define r(x) read(x)
- #define ll long long
- template<typename T>
- inline void read(T&x){
- x=0;T k=1;char gc;
- while(!isdigit(c)){if(c=='-')k=-1;gc;}
- while(isdigit(c)){x=x*10+c-'0';gc;}x*=k;
- }
- const int N=1e5+7;
- struct Node{
- int x,y,v;
- inline bool operator <(const Node &a){
- return x==a.x?y>a.y:x<a.x;
- }
- }a[N];
- int n,tot;
- int t[N];
- ll c[N];
- inline void clear(){
- for(int i=1;i<=tot;++i){
- c[i]=0;
- }
- }
- inline void insert(int x,ll v){
- for(int i=x;i<=tot;i+=(i&-i)){
- c[i]=max(c[i],v);
- }
- }
- inline ll query(int x){
- ll ret=0;
- for(int i=x;i;i^=(i&-i)){
- ret=max(ret,c[i]);
- }
- return ret;
- }
- int main(){
- int T;r(T);
- while(T--){
- r(n);
- tot=0;
- for(int i=1;i<=n;++i){
- r(a[i].x);
- r(a[i].y);
- r(a[i].v);
- t[++tot]=a[i].y;
- }
- sort(t+1,t+tot+1);
- tot=unique(t+1,t+tot+1)-t-1;
- for(int i=1;i<=n;++i){
- a[i].y=lower_bound(t+1,t+tot+1,a[i].y)-t;
- }
- sort(a+1,a+n+1);
- ll ans=0;
- clear();
- for(int i=1;i<=n;++i){
- ll t=query(a[i].y-1)+a[i].v;
- ans=max(ans,t);
- insert(a[i].y,t);
- }
- printf("%lld\n",ans);
- }
- }
- /*
- 2
- 3
- 1 1 1
- 1 2 2
- 3 3 1
- 5
- 1 1 1
- 1 2 2
- 2 1 5
- 3 3 5
- 100 5 10
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement