赶在期末考试之前把这道傻逼题调了出来。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define maxn 100500
using namespace std;
long long n,m,a[maxn];
long long root,tot=,ls[maxn<<],rs[maxn<<];
long long lazy[maxn<<],add[maxn<<],sum[maxn<<],mi[maxn<<],mx[maxn<<];
long long x,y,z;
bool vis[maxn<<];
void pushup(long long now)
{
sum[now]=sum[ls[now]]+sum[rs[now]];
mx[now]=max(mx[ls[now]],mx[rs[now]]);
mi[now]=min(mi[ls[now]],mi[rs[now]]);
}
void build(long long &now,long long left,long long right)
{
now=++tot;lazy[now]=;add[now]=;
if (left==right)
{
sum[now]=mx[now]=mi[now]=a[left];
return;
}
long long mid=(left+right)>>;
build(ls[now],left,mid);
build(rs[now],mid+,right);
pushup(now);
}
void pushdown(long long now,long long left,long long right)
{
long long mid=(left+right)>>;
if (vis[now]==true)
{
lazy[ls[now]]=lazy[rs[now]]=mx[ls[now]]=mx[rs[now]]=mi[ls[now]]=mi[rs[now]]=lazy[now];
sum[ls[now]]=(mid-left+)*lazy[now];
sum[rs[now]]=(right-mid)*lazy[now];
lazy[now]=;vis[now]=false;vis[ls[now]]=vis[rs[now]]=true;
add[ls[now]]=;add[rs[now]]=;
}
if (add[now]!=)
{
add[ls[now]]+=add[now];add[rs[now]]+=add[now];
sum[ls[now]]+=(mid-left+)*add[now];
sum[rs[now]]+=(right-mid)*add[now];
mx[ls[now]]+=add[now];mx[rs[now]]+=add[now];
mi[ls[now]]+=add[now];mi[rs[now]]+=add[now];
add[now]=;
}
}
void modify(long long now,long long left,long long right,long long l,long long r,long long p,long long type)
{
pushdown(now,left,right);
if ((left==l) && (right==r))
{
if (type==)
{
add[now]+=p;sum[now]+=(right-left+)*p;mx[now]+=p;mi[now]+=p;
return;
}
else
{
lazy[now]=p;add[now]=;sum[now]=p*(right-left+);
mx[now]=mi[now]=p;vis[now]=true;
return;
}
}
long long mid=(left+right)>>;
if (r<=mid) modify(ls[now],left,mid,l,r,p,type);
else if (l>=mid+) modify(rs[now],mid+,right,l,r,p,type);
else
{
modify(ls[now],left,mid,l,mid,p,type);
modify(rs[now],mid+,right,mid+,r,p,type);
}
pushup(now);
}
long long ask(long long now,long long left,long long right,long long l,long long r,long long type)
{
pushdown(now,left,right);
if ((left==l) && (right==r))
{
if (type==) return sum[now];
else if (type==) return mx[now];
else return mi[now];
}
long long mid=(left+right)>>;
if (r<=mid) return ask(ls[now],left,mid,l,r,type);
else if (l>=mid+) return ask(rs[now],mid+,right,l,r,type);
else
{
if (type==)
{
long long regis1=ask(ls[now],left,mid,l,mid,type);
long long regis2=ask(rs[now],mid+,right,mid+,r,type);
return regis1+regis2;
}
else if (type==) return max(ask(ls[now],left,mid,l,mid,type),ask(rs[now],mid+,right,mid+,r,type));
else return min(ask(ls[now],left,mid,l,mid,type),ask(rs[now],mid+,right,mid+,r,type));
}
}
int main()
{
memset(vis,false,sizeof(vis));
scanf("%lld%lld",&n,&m);
for (long long i=;i<=n;i++)
scanf("%lld",&a[i]);
build(root,,n);
for (long long i=;i<=m;i++)
{
char type[];
scanf("%s",type);
if (type[]=='a')
{
scanf("%lld%lld%lld",&x,&y,&z);
modify(root,,n,x,y,z,);
}
else if ((type[]=='s') && (type[]=='e'))
{
scanf("%lld%lld%lld",&x,&y,&z);
modify(root,,n,x,y,z,);
}
else if ((type[]=='s') && (type[]=='u'))
{
scanf("%lld%lld",&x,&y);
printf("%lld\n",ask(root,,n,x,y,));
}
else if ((type[]=='m') && (type[]=='a'))
{
scanf("%lld%lld",&x,&y);
printf("%lld\n",ask(root,,n,x,y,));
}
else
{
scanf("%lld%lld",&x,&y);
printf("%lld\n",ask(root,,n,x,y,));
}
}
return ;
}