bzoj2131 免费的馅饼

2018-10-09 16:11:42

$f[i][j]$ 表示时刻 $i$ 在位置 $j$ 的最大收益

$2\times(t[i]-t[j])>=p[i]-p[j]$ 且 $2\times(t[i]-t[j])>=p[j]-p[i]$

$2\times t[i]+p[i]>=2\times t[j]+p[j]$

$2\times t[i]-p[i]>=2\times t[j]-p[j]$

#include<cstdio>
#include<cstring>
#include<cctype>
#include<algorithm>
#define reg register
using namespace std;
const int N=1e5+5;
struct node
{
int tim,pos,val,x,y;
inline friend bool operator < (node a,node b)
{
return a.x==b.x?a.y>b.y:a.x<b.x;
}
}a[N];
int n,W,f[N],c[N],t[N],cnt,ans;
{
int x=0,w=1;
char c=getchar();
while (!isdigit(c)&&c!='-') c=getchar();
if (c=='-') c=getchar(),w=-1;
while (isdigit(c))
{
x=(x<<1)+(x<<3)+c-'0';
c=getchar();
}
return x*w;
}
inline int lowbit(int x){return x&(-x);}
inline void modify(int x,int k){for (;x<=cnt;x+=lowbit(x)) c[x]=max(c[x],k);}
inline int query(int x,int res=0){for (;x;x-=lowbit(x)) res=max(res,c[x]); return res;}
int main()
{
a[0].x=a[0].y=a[0].tim=t[0]=-W;
for (reg int i=1;i<=n;i++)
{
a[i].x=a[i].tim+a[i].pos;
t[i]=a[i].y=a[i].tim-a[i].pos;
}
sort(a,a+n+1); sort(t,t+n+1);
cnt=unique(t,t+n+1)-t-1;
for (reg int i=0;i<=n;i++) a[i].y=lower_bound(t+1,t+cnt+1,a[i].y)-t;
for (reg int i=1;i<=n;i++)
{
f[i]=a[i].val+query(a[i].y);
modify(a[i].y,f[i]); ans=max(ans,f[i]);
}
printf("%d\n",ans);
return 0;
}
• star
首页