萌新求调(悬关玄关
  • 板块灌水区
  • 楼主Tmbcan
  • 当前回复1
  • 已保存回复1
  • 发布时间2024/11/11 13:54
  • 上次更新2024/11/11 14:38:36
查看原帖
萌新求调(悬关玄关
750524
Tmbcan楼主2024/11/11 13:54

KTT 想知道自己的合并有没有写对

const ll INF = 1e16;
struct Func{
	ll k,b;
	Func(){
		k = 0; b = 0;
	}
	Func(ll tk,ll tb){
		k = tk; b = tb;
	}
	inline Func operator + (const Func&G) const{
		return Func(k+G.k,b+G.b);
	}
	inline bool operator < (const Func&G) const{
		return (k==G.k && b<G.b) || k<G.k;
	}
	inline ll operator & (const Func&G) const{
		return (G.b-b)/(k-G.k);
	}
	inline void operator += (const ll&G){
		b += k*G;
	}
};
struct Tree{
	Func lx,rx,sum,mx; ll dx;
	Tree(){
		dx = INF;
	}
	Tree(Func tlx,Func trx,Func tsum,Func tmx,ll tdx){
		lx = tlx; rx = trx; sum = tsum; mx = tmx; dx = tdx;
	}
	inline void Merge_lx(Func x,Func y,Tree &tmp) const{
		if(x<y) swap(x,y);
		if(x.b>=y.b) tmp.lx = x;
		else tmp.lx = y,tmp.dx = Min(tmp.dx,x&y);
	}
	inline void Merge_rx(Func x,Func y,Tree &tmp) const{
		if(x<y) swap(x,y);
		if(x.b>=y.b) tmp.rx = x;
		else tmp.rx = y,tmp.dx = Min(tmp.dx,x&y);
	}
	inline void Merge_mx(Func x,Func y,Tree &tmp) const{
		if(x<y) swap(x,y);
		if(x.b>=y.b) tmp.mx = x;
		else tmp.mx = y,tmp.dx = Min(tmp.dx,x&y);
	}
	inline Tree operator + (const Tree&G) const{
		Tree tmp; tmp.dx = Min(dx,G.dx); tmp.sum = sum+G.sum;
		Merge_lx(lx,sum+G.lx,tmp);Merge_rx(G.rx,G.sum+rx,tmp);
		Merge_mx(G.mx,mx,tmp);Merge_mx(tmp.mx,rx+G.lx,tmp);
		return tmp;
	}
	inline void operator += (const ll&G){
		lx += G; rx += G; mx += G; sum += G; dx -= G;
	}
}tr[N*3];
int P=1,DEP=0,st[N*3]; ll tag[N*3];
inline void push_up(int p){
	tr[p] = tr[p<<1]+tr[p<<1|1];
}
inline void cover(int p,ll k){
	tag[p] += k; tr[p] += k;
}
inline void push_down(int p){
	if(!tag[p]) return ;
	cover(p<<1,tag[p]); cover(p<<1|1,tag[p]);
	tag[p] = 0;
}
2024/11/11 13:54
加载中...