Free Pies bzoj-2131
Main Topic :
Note : $1\le n \le 10^5$,$1\le w \le 10^8$.
idea : First, think of DP
status : Dp[i][j] represents the maximum benefit of I minute in position J
Optimized optimization
status : Dp[i] Indicates the maximum benefit of the last received I.
Transfer : Order enumeration i:1->n.
then , we try to optimize
For this state we will find that there is an absolute dead thing at the time of transfer, and we take it apart:
2*t[j]+pos[j]<=2*t[i]+pos[i] and 2*t[j]-pos[j]<=2*t[i]-pos[i]
Then, by subtracting the subscript, the addition is updated on the tree-shaped array.
finally , attach the ugly code ...
#include <iostream> #include <cstdio> #include <cstring># Include <algorithm>using namespace Std;int w,n,f[100010],hash[100010],cnt,ans,s[100010];struct pies{int t,p,v, W1,W2;} A[100010];int CMP (const pies &a,const pies &b) {return a.w1<b.w1;} int lowbit (int x) {return x& (-X);} int ask (int i) {int max=0;while (i!=0) {Max=max (max,s[i]); I-=lowbit (i);} return Max;} void Add (int i,int val) {while (i<=cnt) {S[i]=max (s[i],val); i+=lowbit (i);}} int main () {scanf ("%d%d", &w,&n), for (int i=1;i<=n;i++) {scanf ("%d%d%d", &a[i].t,&a[i].p,&a[i] . v); a[i].t*=2;a[i].w1=a[i].t-a[i].p;a[i].w2=a[i].t+a[i].p;hash[++cnt]=a[i].w2;} Sort (hash+1,hash+cnt+1); Cnt=unique (hash+1,hash+cnt+1)-hash-1;for (int i=1;i<=n;i++) {A[i].w2=lower_bound (hash+ 1,HASH+CNT+1,A[I].W2)-hash;} Sort (a+1,a+n+1,cmp), for (int i=1;i<=n;i++) {f[i]=ask (A[I].W2) +a[i].v;ans=max (Ans,f[i]), add (A[i].w2,f[i]);} printf ("%d\n", ans); return 0;}
Summary : None.
[bzoj2131] Free Pies _ tree-like array