# 洛谷3571 POI2014 SUP-Supercomputer （斜率优化）

qwq

$$sum[i]$$表示深度大于等于$$i$$的点有多少个。

qwq现在来解释一下为什么是这个柿子。

$\lceil \frac{sum[j+1]}{k} \rceil > \lceil \frac{sum[i+1]}{k} \rceil + (i-j)$

$\lceil \frac{sum[j+1]}{k} \rceil + j> \lceil \frac{sum[i+1]}{k} \rceil + i$

qwq

$f[i]=max(j+\lceil \frac{sum[j+1]}{i} \rceil)$

$f[i]=max(\lceil \frac{j\times i+ sum[j+1]}{i} \rceil)$

$j\times i + sum[j+1] > k \times i + sum[k+1]$

$$sum$$数组可以直接通过前缀和求出来

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#define mk make_pair
#define ll long long
using namespace std;
{
int x=0,f=1;char ch=getchar();
while (!isdigit(ch)) {if (ch=='-') f=-1;ch=getchar();}
while (isdigit(ch)) {x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}
return x*f;
}
const int maxn = 1e6+1e2;
int sum[maxn];
int n,m;
int point[maxn],nxt[maxn],to[maxn];
int cnt;
int deep[maxn];
int dp[maxn];
int a[maxn];
{
nxt[++cnt]=point[x];
to[cnt]=y;
point[x]=cnt;
}
struct Point{
ll x,y,num;
};
Point q[maxn];
ll chacheng(Point x,Point y)
{
return x.x*y.y-x.y*y.x;
}
bool Count(Point i,Point j,Point k)
{
Point x,y;
x.x=k.x-i.x;
x.y=k.y-i.y;
y.x=k.x-j.x;
y.y=k.y-j.y;
if (chacheng(x,y)>=0) return true;
return false;
}
void push(Point x)
{
q[++tail]=x;
}
void pop(int lim)
{
}
int mx;
void dfs(int x,int dep)
{
deep[dep]++;
mx=max(mx,dep);
for (int i=point[x];i;i=nxt[i])
{
int p = to[i];
dfs(p,dep+1);
}
}
int qq;
int main()
{
int ymh =0;
for (int i=2;i<=n;i++)
{
}
dfs(1,1);
for (int i=mx;i>=0;i--)
{
deep[i]+=deep[i+1];
}
for (int i=0;i<mx;i++)
push((Point){i,deep[i+1],i});

for (register int i=1;i<=ymh;++i)
{
pop((-1)*i);