序列操作
【问题描述】
给出一个有n个元素的的数组:A[1],A[2],…,A[n],你的任务是设计一个数据结构,支持以下三种操作:
1 L R v:把A[L],A[L+1],…A[R]都增加v(v>=0)。
2 L R v:把A[L],A[L+1],…A[R]都修改成(v>=0)。
3 L R:计算A[L],A[L+1],…A[R]的元素和、最小值和最大值。
输入保证任意时刻序列中所有元素和不超过10^9。
【输入格式】
第一行包含 2 个正整数:n 和 m 。以下n行,每行一个整数,表示 A[i]。再以下 m 行,每行为上述三种操作之一。
【输出格式】
针对操作类型3,依次输出元素和、最小值和最大值。
【输入样例】
10 7
1 2 3 4 5 6 7 8 9 10
3 4 8
1 3 7 2
2 4 8 5
3 3 7
1 6 9 1
2 3 5 0
3 4 7
【输出样例】
30 4 8
25 5 5
12 0 6
【数据范围】
1<=m,n<=100 000。
最初始的|A[i]|<=100。
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<vector>
#include<cctype>
using namespace std;
const int maxn=100005;
int minv[2*maxn],np,rt,maxv[2*maxn],sum[2*maxn],add[2*maxn],setv[2*maxn],a[maxn],lc[2*maxn],rc[2*maxn];
int n,m,ch,x,y,d;
void initial()
{
rt=np=0;
for(int i=1;i<=2*n;i++) setv[i]=-1;
memset(lc,0,sizeof(lc));
memset(rc,0,sizeof(rc));
}
void pushup(int now)
{
minv[now]=min(minv[lc[now]],minv[rc[now]]);
maxv[now]=max(maxv[lc[now]],maxv[rc[now]]);
sum[now]=sum[lc[now]]+sum[rc[now]];
}
void pushdowncha(int now,int L,int R)
{
if(setv[now]>=0)
{
int m=(L+R)>>1;
add[lc[now]]=0;
add[rc[now]]=0;
maxv[lc[now]]=minv[lc[now]]=maxv[rc[now]]=minv[rc[now]]=setv[now];
sum[lc[now]]=(m-L+1)*setv[now];
sum[rc[now]]=(R-m)*setv[now];
setv[lc[now]]=setv[now];
se