比赛 4043级2023省选练习赛5 评测结果 AAAAAATTTT
题目名称 市场 最终得分 60
用户昵称 瑆の時間~無盡輪迴·林蔭 运行时间 11.915 s
代码语言 C++ 内存使用 17.37 MiB
提交时间 2023-03-13 21:28:43
显示代码纯文本
#include<iostream>
#include<cstdio>
#include<cmath>
#define int long long 
using namespace std;
const int N=100001;
int val[4*N],mi[4*N],mx[4*N],lazy[4*N],cl[4*N],ch[4*N];
int a[N];
int ls(int x)
{
	return x<<1;
}
int rs(int x)
{
	return x<<1|1;
}
void pushup(int x)
{
	val[x]=val[ls(x)]+val[rs(x)];
	mi[x]=min(mi[ls(x)],mi[rs(x)]);
	mx[x]=max(mx[ls(x)],mx[rs(x)]);
}
void pushdown(int x,int l,int r)
{
	if(ch[x])
	{
		int mid=(l+r)>>1;
		val[ls(x)]=(mid-l+1)*cl[x];
		val[rs(x)]=(r-mid)*cl[x];
		mi[ls(x)]=cl[x];
		mx[ls(x)]=cl[x];
		mi[rs(x)]=cl[x];
		mx[rs(x)]=cl[x];
		cl[ls(x)]=cl[x];
		cl[rs(x)]=cl[x];
		lazy[ls(x)]=0;
		lazy[rs(x)]=0;
		ch[ls(x)]=1;
		ch[rs(x)]=1;
		ch[x]=0;
		cl[x]=0;
		return;
	}
	if(lazy[x])
	{
		int mid=(l+r)>>1;
		val[ls(x)]+=(mid-l+1)*lazy[x];
		val[rs(x)]+=(r-mid)*lazy[x];
		mi[ls(x)]+=lazy[x];
		mi[rs(x)]+=lazy[x];
		mx[ls(x)]+=lazy[x];
		mx[rs(x)]+=lazy[x];
		if(ch[ls(x)])
		{
			cl[ls(x)]+=lazy[x];
		}
		else
			lazy[ls(x)]+=lazy[x];
		if(ch[rs(x)])
		{
			cl[rs(x)]+=lazy[x];
		}
		else
			lazy[rs(x)]+=lazy[x];
		lazy[x]=0;
	}
}
void Build(int x,int l,int r)
{
	if(l==r)
	{
		val[x]=a[l];
		mx[x]=a[l];
		mi[x]=a[l];
		return;
	}
	int mid=(l+r)>>1;
	Build(ls(x),l,mid);
	Build(rs(x),mid+1,r);
	pushup(x); 
}
void ADD(int x,int l,int r,int nl,int nr,int V)
{
	if(nl<=l&&nr>=r)
	{
		val[x]+=(r-l+1)*V;
		if(ch[x])
		{
			cl[x]+=V;
		}
		else
			lazy[x]+=V;
		mi[x]+=V;
		mx[x]+=V;
		return;
	}
	pushdown(x,l,r);
	int mid=(l+r)>>1;
	if(nl<=mid)
		ADD(ls(x),l,mid,nl,nr,V);
	if(nr>mid)
	{
		ADD(rs(x),mid+1,r,nl,nr,V);
	}
	pushup(x);
}
void CHANGE(int x,int l,int r,int nl,int nr,int KEL)
{
	if(nl<=l&&nr>=r)
	{
		int mid=(l+r)>>1;
		if(floor(((double)mx[x])/KEL)==floor((double)mi[x]/KEL))
		{
			int D=floor((double)mx[x]/KEL);
			lazy[x]=0;
			ch[x]=1;
			cl[x]=D;
			val[x]=(r-l+1)*D;
			mi[x]=D;
			mx[x]=D;
			return;
		}
		else
		{
			pushdown(x,l,r);
			CHANGE(ls(x),l,mid,nl,nr,KEL);
			CHANGE(rs(x),mid+1,r,nl,nr,KEL);
		}
	}
	else
	{
		pushdown(x,l,r);
		int mid=(l+r)>>1;
		if(nl<=mid)
		{
			CHANGE(ls(x),l,mid,nl,nr,KEL);
		}
		if(nr>mid)
			CHANGE(rs(x),mid+1,r,nl,nr,KEL);
	}
	pushup(x);
}
int Query1(int x,int l,int r,int nl,int nr)
{
	if(nl<=l&&nr>=r)
	{
		return val[x];
	}
	pushdown(x,l,r);
	int mid=(l+r)>>1,ans=0;
	if(nl<=mid)
	{
		ans+=Query1(ls(x),l,mid,nl,nr);
	} 
	if(nr>mid)
	{
		ans+=Query1(rs(x),mid+1,r,nl,nr);
	}
	return ans;
}
int Query2(int x,int l,int r,int nl,int nr)
{
	if(nl<=l&&nr>=r)
	{
		return mi[x];
	}
	pushdown(x,l,r);
	int mid=(l+r)>>1,ans=998244353;
	if(nl<=mid)
		ans=min(ans,Query2(ls(x),l,mid,nl,nr));
	if(nr>mid)
		ans=min(ans,Query2(rs(x),mid+1,r,nl,nr));
	return ans;
}
int CHECK(int x,int l,int r,int pos)
{
	if(l==r)
	{
		return val[x];
	}
	pushdown(x,l,r);
	int mid=(l+r)>>1;
	if(pos<=mid)
	return CHECK(ls(x),l,mid,pos);
	else
	return CHECK(rs(x),mid+1,r,pos);
}
int n,q;
signed main()
{
	freopen("2017market.in","r",stdin);
	freopen("2017market.out","w",stdout);
	scanf("%lld%lld",&n,&q);
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]);
	}
	Build(1,1,n);
	int a1,a2,a3,a4;
	for(int i=1;i<=q;i++)
	{
		cin>>a1>>a2>>a3;
		a2++;
		a3++;
		if(a1<=2)
			cin>>a4;
		if(a1==1)
		{
			ADD(1,1,n,a2,a3,a4);
		}
		if(a1==2)
		{
			CHANGE(1,1,n,a2,a3,a4);
		}
		if(a1==3)
			cout<<Query2(1,1,n,a2,a3)<<endl;
		if(a1==4)
			cout<<Query1(1,1,n,a2,a3)<<endl;
	}
	return 0;
}