Topic links: https://ac.nowcoder.com/acm/contest/881/I
Subject to the effect:
Analysis n points, each point has a, b two attributes, from the lower left to the upper right corner so you draw a line, the contribution of each point of the left edge is to the right of $ a_ {i} $, each line point is the contribution of $ b_ {i} $, such that the maximum sum of two parts. I.e., $ max (\ sum_ {i \ epsilon A} a_ {i}) + (\ sum_ {i \ epsilon B} b_ {i}) $, and meet when $ i \ epsilon A $, $ j \ epsilon B $ when, $ x_ {i} \ geq x_ {j} $ and $ y_ {i} \ leq y_ {j} $.
Report problem solving:
Firstly y coordinates discrete, considering this line via a plurality of point B, if the current point to take a, then prior to contributions lower than its points are a, if the current point to take B, then before than it contribution points are b, b and then have to consider whether to choose the current point, interval maintenance dp, using segment tree.
AC Code:
1 #include<bits/stdc++.h> 2 #define numm ch-48 3 #define pd putchar(' ') 4 #define pn putchar('\n') 5 #define pb push_back 6 #define fi first 7 #define se second 8 #define fre1 freopen("1.txt","r",stdin) 9 #define fre2 freopen("3.txt","w",stdout) 10 #define bug cout<<"*******************"<<endl; 11 #define debug(args...) cout<<#args<<"->"<<args<<"\n"; 12 using namespace std; 13 template <typename T> 14 void read(T &res) { 15 bool flag=false;char ch; 16 while(!isdigit(ch=getchar())) (ch=='-')&&(flag=true); 17 for(res=numm;isdigit(ch=getchar());res=(res<<1)+(res<<3)+numm); 18 flag&&(res=-res); 19 } 20 template <typename T> 21 void write(T x) { 22 if(x<0) putchar('-'),x=-x; 23 if(x>9) write(x/10); 24 putchar(x%10+'0'); 25 } 26 typedef long long ll; 27 typedef unsigned long long ull; 28 const int maxn=100010; 29 const int maxm=505; 30 const int mod=1e9+7; 31 const int inv2=500000004; 32 const int inf=0x3f3f3f3f; 33 const ll INF=0x3f3f3f3f3f3f3f3f; 34 const int N=32; 35 struct node { 36 int a,b,x,y; 37 bool operator<(const node &z) { 38 return x==z.x?y>z.y:x<z.x; 39 } 40 }p[maxn]; 41 struct ST { 42 #define ls (k<<1) 43 #define rs (k<<1|1) 44 struct node { 45 int l,r; 46 ll maxx,lazy; 47 }st[maxn<<2]; 48 void pushup(int k) { 49 st[k].maxx=max(st[ls].maxx,st[rs].maxx); 50 } 51 void pushdown(int k) { 52 st[ls].maxx+=st[k].lazy; 53 st[ls].lazy+=st[k].lazy; 54 st[rs].maxx+=st[k].lazy; 55 st[rs].lazy+=st[k].lazy; 56 st[k].lazy=0; 57 } 58 void build(int k,int l,int r) { 59 st[k]=node{l,r,0,0}; 60 if(l==r) { 61 st[k].maxx=-INF; 62 st[k].lazy=0; 63 return ; 64 } 65 int mid=(l+r)>>1; 66 if(l<=mid) build(ls,l,mid); 67 if(mid<r) build(rs,mid+1,r); 68 pushup(k); 69 } 70 void add(int k,int l,int r,ll x) { ///区间修改 71 if(l>r) return ; 72 if(st[k].l==l&&st[k].r==r) { 73 st[k].maxx+=x; 74 st[k].lazy+=x; 75 return ; 76 } 77 if(st[k].lazy) pushdown(k); 78 int mid=(st[k].l+st[k].r)>>1; 79 if(mid>=r) add(ls,l,r,x); 80 else if(mid<l) add(rs,l,r,x); 81 else { 82 add(ls,l,mid,x); 83 add(rs,mid+1,r,x); 84 } 85 pushup(k); 86 } 87 void update(int k,int pos,ll x) { /// single point modification for optimizing the value (DP) 88 IF (ST [K] .L == ST [K] .r) { 89 ST [K] .maxx = max (ST [K] .maxx, X); 90 return ; 91 is } 92 IF (ST [K] .lazy) pushdown (K); 93 int MID = (ST [K] .L + ST [K] .r) >> . 1 ; 94 IF (MID > = POS) Update (LS, POS, X); 95 the else IF (MID < POS) Update (RS, POS, X); 96 a pushup (K); 97 } 98 LL querymax ( int K, int L,int r) { ///区间查询 99 if(l>r) return 0; 100 if(st[k].l==l&&st[k].r==r) return st[k].maxx; 101 if(st[k].lazy) pushdown(k); 102 int mid=(st[k].l+st[k].r)>>1; 103 if(mid>=r) return querymax(ls,l,r); 104 else if(mid<l) return querymax(rs,l,r); 105 else return max(querymax(ls,l,mid),querymax(rs,mid+1,r)); 106 } 107 }wtz; 108 int t[maxn]; 109 int main() 110 { 111 // #define local 112 #ifdef local 113 fre1; 114 fre2; 115 #endif // local 116 int n,m; 117 while(scanf("%d",&n)!=EOF) { 118 int tot=0; 119 for(int i=1;i<=n;i++) { 120 read(p[i].x),read(p[i].y); 121 read(p[i].a),read(p[i].b); 122 t[++tot]=p[i].y; 123 } 124 sort(t+1,t+1+n); 125 tot=unique(t+1,t+1+n)-t-1; 126 for(int i=1;i<=n;i++) ///离散化 127 p[i].y=lower_bound(t+1,t+1+tot,p[i].y)-t+1; ///Segment tree from 1 to p [i] .y-1, p [i] .y at least 2 128 Sort (P + 1 , P + 1 + n-); 129 TOT ++; /// total interval plus 1, so the TOT ++ 130. WTZ .build ( . 1 , . 1 , TOT); 131 is wtz.update ( . 1 , . 1 , 0 ); /// new high point 0 of 132 for ( int I = . 1 ; I <= n-; I ++ ) { 133 LL wtz.querymax = now ( . 1 , . 1 , P [I] .y); 134 wtz.update ( . 1, P [I] .y, now + P [I] .B); 135 wtz.add ( . 1 , P [I] .y + . 1 , TOT, P [I] .B); /// for the current selected point b then, before it will be higher than the selected 136 wtz.add ( . 1 , . 1 , P [I] .y- . 1 , P [I] II.A); /// for the current point of a selected, than previous it will be low selected 137 } 138 Write (wtz.st [ . 1 ] .maxx); PN; 139 } 140 return 0 ; 141 is }