2586 区间最大子段和
题目详情见 [Ynoi2018] 末日时在做什么?有没有空?可以来拯救吗?
这里只放代码:
#include<cstdio>
#include<algorithm>
using namespace std;const int N=1e5+10;const int B=110;typedef long long ll;int n;int m;const ll minf=-(1LL<<47);//点结构体,叉积计算
struct poi{ll x;ll y;friend poi operator +(poi a,poi b){return (poi){a.x+b.x,a.y+b.y};}};
inline bool cmp(const poi& a,const poi& b,const poi& c){return (a.y-c.y)*(a.x-b.x)>=(a.y-b.y)*(a.x-c.x);}
inline bool cmp(const poi& a,const poi& b,const ll& k){return k*(b.x-a.x)>=b.y-a.y;}
inline bool cmp(const poi& a,const poi& b,const poi& c,const poi& d)
{return (c.y-d.y)*(a.x-b.x)>=(a.y-b.y)*(c.x-d.x);}
inline void chull(poi* st,int& tp)//jarvis水平步进法求凸包
{int i,r;for(i=2,r=tp,tp=1;i<=r;i++){while(tp>1&&cmp(st[tp-1],st[tp],st[i]))tp--;st[++tp]=st[i];}}
struct data//最大子段和的结构体
{
ll sum;ll l;ll r;ll ans;
friend data operator +(data a,data b)
{return (data){a.sum+b.sum,max(a.sum+b.l,a.l),max(a.r+b.sum,b.r),max(a.r+b.l,max(a.ans,b.ans))};}
};poi st[B+10];