社区讨论

50pts板子求调(悬关)

P1253扶苏的问题参与者 2已保存回复 2

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
2 条
当前快照
1 份
快照标识符
@lo13xp9u
此快照首次捕获于
2023/10/22 14:48
2 年前
此快照最后确认于
2023/11/02 14:19
2 年前
查看原帖
CPP
#include<bits/stdc++.h>
#define lo (nw<<1)
#define ro (nw<<1|1)
#define md ((l+r)>>1)
using namespace std;

const int N=1000010,INF=0x3f3f3f3f;

int n,q;
int a[N];

struct node
{
	int sm,sz;
	int ch,pl;
	int mx;
}t[5*N];

struct segment_tree
{
	void upd(int nw)
	{
		t[nw].sm=t[lo].sm+t[ro].sm;
		t[nw].sz=t[lo].sz+t[ro].sz;
		t[nw].mx=max(t[lo].mx,t[ro].mx);
		return ;
	}
	void mkpl(int nw,int z)
	{
		t[nw].pl=t[nw].pl+z;
		t[nw].sm=t[nw].sm+t[nw].sz*z;
		t[nw].mx=t[nw].mx+z;
		return ;
	}
	void mkch(int nw,int z)
	{
		t[nw].ch=z;
		t[nw].sm=t[nw].sz*z;
		t[nw].pl=0;
		t[nw].mx=z;
		return ;
	}
	void psd(int nw)
	{
		if(t[nw].ch!=INF)
		{
			mkch(lo,t[nw].ch);
			mkch(ro,t[nw].ch);
			t[nw].ch=INF;
		}
		if(t[nw].pl!=0)
		{
			mkpl(lo,t[nw].pl);
			mkpl(ro,t[nw].pl);
			t[nw].pl=0;
		}
		return ;
	}
	void bld(int nw,int l,int r)
	{
		t[nw].pl=0;
		t[nw].ch=INF;
		if(l==r)
		{
			t[nw].sm=a[l];
			t[nw].sz=1;
			t[nw].mx=a[l];
			return ;
		}
		bld(lo,l,md);
		bld(ro,md+1,r);
		upd(nw);
		return ;
	}
	void atp(int nw,int l,int r,int x,int y,int z)
	{
		if(x<=l&&r<=y)
		{
			mkpl(nw,z);
			return ;
		}
		psd(nw);
		if(x<=md)
			atp(lo,l,md,x,y,z);
		if(y>md)
			atp(ro,md+1,r,x,y,z);
		upd(nw);
		return ;
	}
	void atc(int nw,int l,int r,int x,int y,int z)
	{
		if(x<=l&&r<=y)
		{
			mkch(nw,z);
			return ;
		}
		psd(nw);
		if(x<=md)
			atc(lo,l,md,x,y,z);
		if(y>md)
			atc(ro,md+1,r,x,y,z);
		upd(nw);
		return ;
	}
	int qry(int nw,int l,int r,int x,int y)
	{
		if(x<=l&&r<=y)
		{
			return t[nw].mx;
		}
		psd(nw);
		int maxx=-INF;
		if(x<=md)
			maxx=max(maxx,qry(lo,l,md,x,y));
		if(y>md)
			maxx=max(maxx,qry(ro,md+1,r,x,y));
		return maxx;
	}
}ST;

signed main()
{
	cin>>n>>q;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	ST.bld(1,1,n);
	for(int i=1;i<=q;i++)
	{
		int op,l,r,x;
		cin>>op;
		if(op==1)
		{
			cin>>l>>r>>x;
			ST.atc(1,1,n,l,r,x);
		}
		if(op==2)
		{
			cin>>l>>r>>x;
			ST.atp(1,1,n,l,r,x);
		}
		if(op==3)
		{
			cin>>l>>r;
			cout<<ST.qry(1,1,n,l,r)<<"\n";
		}
	}
	return 0;
}

回复

2 条回复,欢迎继续交流。

正在加载回复...