标签:map sub lin node == -- 而且 pac 移动
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 253 Accepted Submission(s): 62
1 #include <bits/stdc++.h> 2 #define mid ((tr[d].l + tr[d].r)>>1) 3 #define lc (d << 1) 4 #define rc (d << 1|1) 5 using namespace std; 6 const int maxn = 1e5+5; 7 struct Tr{ 8 int l,r,mx; 9 }tr[maxn*4]; 10 struct Node{ 11 int x,y,w; 12 bool operator < (const Node &a)const{ 13 //????? 14 return (x == a.x) ? y > a.y : x < a.x; 15 } 16 }node[maxn]; 17 int T,n; 18 int hash_x[maxn],hash_y[maxn]; 19 int n1,n2; 20 21 void build(int d,int l,int r){ 22 tr[d].l = l,tr[d].r = r,tr[d].mx = 0; 23 if (tr[d].l == tr[d].r){ 24 return; 25 } 26 build(lc,l,mid); build(rc,mid+1,r); 27 } 28 29 int query(int d,int l,int r){ 30 if (tr[d].l == l && tr[d].r == r){ 31 return tr[d].mx; 32 } 33 if (mid >= r) return query(lc,l,r); 34 else if (mid < l) return (rc,l,r); 35 else return max(query(lc,l,mid),query(rc,mid+1,r)); 36 } 37 38 void update(int d,int pos,int w){ 39 if (tr[d].l == tr[d].r && tr[d].r == pos) { 40 tr[d].mx = max(w,tr[d].mx); 41 return; 42 } 43 if (mid >= pos) update(lc,pos,w); 44 else update(rc,pos,w); 45 tr[d].mx = max(tr[lc].mx,tr[rc].mx); 46 } 47 48 int main(){ 49 scanf("%d",&T); 50 while(T--){ 51 scanf("%d",&n); 52 for (int i = 0;i < n;++i){ 53 scanf("%d%d%d",&node[i].x,&node[i].y,&node[i].w); 54 hash_x[i] = node[i].x,hash_y[i] = node[i].y; 55 } 56 sort(hash_x,hash_x+n); 57 sort(hash_y,hash_y+n); 58 n1 = unique(hash_x,hash_x+n) - hash_x; 59 n2 = unique(hash_y,hash_y+n) - hash_y; 60 for (int i = 0;i < n;++i){ 61 node[i].x = lower_bound(hash_x,hash_x+n1,node[i].x) - hash_x; 62 node[i].y = lower_bound(hash_y,hash_y+n2,node[i].y) - hash_y; 63 } 64 sort(node,node+n); 65 build(1,0,n); 66 int ans = 0; 67 for (int i = 0;i < n;++i){ 68 int tmp; 69 if (node[i].y == 0) tmp = node[i].w; 70 else tmp = query(1,0,node[i].y-1) + node[i].w; 71 update(1,node[i].y,tmp); 72 ans = max(ans,tmp); 73 } 74 printf("%d\n",ans); 75 } 76 return 0; 77 }
HDU6447 YJJ's Salesman 2018中国大学生程序设计竞赛 - 网络选拔赛1010 离散化+线段树+DP
标签:map sub lin node == -- 而且 pac 移动
原文地址:https://www.cnblogs.com/mizersy/p/9535259.html