跳到正文

个人记录

打包结构体

zzr8178541919约 1 分钟
原文
文章信息与版本

文章信息

发布
2021年1月20日
收录
2025年12月12日
更新
2026年11月19日
篇幅
约 1 分钟

版本

  1. v1当前

打包结构体:

打包结构体是一种非常好看的写法,把函数包在结构体中,很方便。

C++
struct Segment_Tree
{
	void update(int x)
	{
		T[x].wns=min(T[x*2].wns,T[x*2+1].wns);
	}
	void build(int x,int l,int r)
	{
		T[x].l=l,T[x].r=r;
		T[x].wns=INF;
		if(l==r)
		{
			T[x].wns=abs(b[l]-b[l-1]);
			return;
		}
		int mid=(l+r)>>1;
		build(x*2,l,mid);
		build(x*2+1,mid+1,r);
		update(x);
	}
	void Work(int x,int t,int val)
	{
		if(T[x].l==T[x].r)
		{
			T[x].wns=val;
			return;
		}
		int mid=(T[x].l+T[x].r)>>1;
		if(t<=mid)
		Work(x*2,t,val);
		else
		Work(x*2+1,t,val);
		update(x);
	}
}Segment_Tree;
原文