[SDOI2013] 保护出题人的坟墓 题解
作为SDOI的选手,保护出题人的坟墓是他们的神圣职责!
提供一个在线的、简单的做法。
对于一些僵尸,首先我们要在第一个僵尸毁坏出题人的坟墓之前干掉他,然后是第二个之前干掉前两个,第三个之前干掉前三个...
设有
把分子分母分别转换成坐标的
但是... 怎么加入点?由于是在前面加的,
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef __int128 LL;
typedef pair<ll,ll> pii;
double ans;
ll n,d,a[200005],dis[200005];
ll px,py,v,vv,l,r;
pii p[200005],pos[200005];
double getslp(pii x){return 1.0*(x.second-py)/(x.first-px);}
bool cmpslp(pii x,pii y,pii z)
{
LL justone=1;
if(justone*(y.second-x.second)*(z.first-y.first)>justone*(z.second-y.second)*(y.first-x.first)) return true;
return false;
}
void ins(ll x)
{
py-=x;
p[v]={-v*d,py+x};
while(vv>=2&&!cmpslp(p[v],pos[vv],pos[vv-1])) vv--;
pos[++vv]=p[v];
}
void getans(ll x)
{
double res=0.0;
px=-v*d-x;
l=1,r=vv;
while(l+5<r)
{
ll lmd=(2*l+r)/3,rmd=(l+r*2)/3;
double lres=getslp(pos[lmd]),rres=getslp(pos[rmd]);
res=max(res,max(lres,rres));
if(cmpslp({px,py},pos[lmd],pos[rmd])) r=rmd;
else l=lmd;
}
for(int i=l;i<=r;i++) res=max(res,getslp(pos[i]));
ans+=res;
}
int main()
{
scanf("%lld%lld",&n,&d);
for(int i=1;i<=n;i++) scanf("%lld%lld",&a[i],&dis[i]);
for(int i=1;i<=n;i++)
{
v=i;
ins(a[i]);
getans(dis[i]);
}
printf("%lld\n",(ll)(ans+0.5));
return 0;
}