线段树求调
  • 板块灌水区
  • 楼主feEr
  • 当前回复0
  • 已保存回复0
  • 发布时间2025/1/14 16:32
  • 上次更新2025/1/14 20:17:56
查看原帖
线段树求调
1383338
feEr楼主2025/1/14 16:32

没问题也说一声行吗

struct tree
{
	struct node
	{
		int l,r;
		node *lson,*rson;
		int maxs;
		int set_tag;
		node();
		node(int l,int r):l(l),r(r),lson(nullptr),rson(nullptr),maxs(0),set_tag(0){}
	} *root;
	#define init \
		int &l=Node->l,&r=Node->r; \
		node *&lson=Node->lson,*&rson=Node->rson; \
		int &maxs=Node->maxs; \
		int &set_tag=Node->set_tag;
	void upd(node *Node)
	{
		init;
		int mid=l+r>>1;
		if(lson==nullptr)
			lson=new node(l,mid);
		if(rson==nullptr)
			rson=new node(mid+1,r);
	}
	void modify(node *Node,int x,int y,int v)
	{
		init;
		if(y<l||r<x)
			return;
		maxs=v;
		if(x<=l&&r<=y)
		{
			set_tag=v;
			return;
		}
		upd(Node);
		modify(lson,x,y,v);
		modify(rson,x,y,v);
	}
	int query(node *Node,int x,int y)
	{
		init;
		if(y<l||r<x)
			return 0;
		int ans=set_tag;
		if(x<=l&&r<=y)
			return ans=max(ans,maxs);
		upd(Node);
		ans=max(ans,query(lson,x,y));
		ans=max(ans,query(rson,x,y));
		return ans;
	}
	tree(){}
	tree(int l,int r):root(new node(l,r)){}
	#undef init
};
2025/1/14 16:32
加载中...