Advertisement
yicongli

HDU6447

Mar 17th, 2019
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.38 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. #define gc c=getchar()
  6. #define r(x) read(x)
  7. #define ll long long
  8.  
  9. template<typename T>
  10. inline void read(T&x){
  11.     x=0;T k=1;char gc;
  12.     while(!isdigit(c)){if(c=='-')k=-1;gc;}
  13.     while(isdigit(c)){x=x*10+c-'0';gc;}x*=k;
  14. }
  15.  
  16. const int N=1e5+7;
  17.  
  18. struct Node{
  19.     int x,y,v;
  20.     inline bool operator <(const Node &a){
  21.         return x==a.x?y>a.y:x<a.x;
  22.     }
  23. }a[N];
  24.  
  25. int n,tot;
  26. int t[N];
  27. ll c[N];
  28.  
  29. inline void clear(){
  30.     for(int i=1;i<=tot;++i){
  31.         c[i]=0;
  32.     }
  33. }
  34.  
  35. inline void insert(int x,ll v){
  36.     for(int i=x;i<=tot;i+=(i&-i)){
  37.         c[i]=max(c[i],v);
  38.     }
  39. }
  40.  
  41. inline ll query(int x){
  42.     ll ret=0;
  43.     for(int i=x;i;i^=(i&-i)){
  44.         ret=max(ret,c[i]);
  45.     }
  46.     return ret;
  47. }
  48.  
  49. int main(){
  50.     int T;r(T);
  51.     while(T--){
  52.         r(n);
  53.         tot=0;
  54.         for(int i=1;i<=n;++i){
  55.             r(a[i].x);
  56.             r(a[i].y);
  57.             r(a[i].v);
  58.             t[++tot]=a[i].y;
  59.         }
  60.         sort(t+1,t+tot+1);
  61.         tot=unique(t+1,t+tot+1)-t-1;
  62.         for(int i=1;i<=n;++i){
  63.             a[i].y=lower_bound(t+1,t+tot+1,a[i].y)-t;
  64.         }
  65.         sort(a+1,a+n+1);
  66.         ll ans=0;
  67.         clear();
  68.         for(int i=1;i<=n;++i){
  69.             ll t=query(a[i].y-1)+a[i].v;
  70.             ans=max(ans,t);
  71.             insert(a[i].y,t);
  72.         }
  73.         printf("%lld\n",ans);
  74.     }
  75. }
  76. /*
  77. 2
  78. 3
  79. 1 1 1
  80. 1 2 2
  81. 3 3 1
  82. 5
  83. 1 1 1
  84. 1 2 2
  85. 2 1 5
  86. 3 3 5
  87. 100 5 10
  88.  
  89. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement