FHQTreap裸题...
用文艺平衡树的方法,维护区间和然后一直Push_Down就可以了(60行代码暴力AC)
//张家奇怎么又AKIOI了呀,怎么CSP也满分啊...怎么清北天天给他打电话啊...怎么会有这么强的人啊
#include<bits/stdc++.h>
#define int long long
#define writeln(x) write(x),puts("")
#define writep(x) write(x),putchar(' ')
using namespace std;
inline int read(){
int ans=,f=;char chr=getchar();
while(!isdigit(chr)){if(chr=='-') f=-;chr=getchar();}
while(isdigit(chr)){ans=(ans<<)+(ans<<)+chr-;chr=getchar();}
return ans*f;
}void write(int x){
if(x<) putchar('-'),x=-x;
if(x>) write(x/);
putchar(x%+'');
}const int M = 2E5+;
int n,m,cnt,x,y,z,root;
struct FHQ_Treap{int x,ls,rs,sz,lz,sum,key;}s[M];
inline int NewNode(int val){s[++cnt]=(FHQ_Treap){val,,,,,val,rand()};return cnt;}
inline void Push_Up(int i){s[i].sum=s[s[i].ls].sum+s[s[i].rs].sum+s[i].x;s[i].sz=s[s[i].ls].sz+s[s[i].rs].sz+;}
inline void Push_Down(int i){
if(!s[i].lz) return;
s[s[i].ls].lz+=s[i].lz,s[s[i].rs].lz+=s[i].lz;
s[s[i].ls].x+=s[i].lz,s[s[i].rs].x+=s[i].lz;
s[s[i].ls].sum+=s[i].lz*s[s[i].ls].sz;
s[s[i].rs].sum+=s[i].lz*s[s[i].rs].sz;
s[i].lz=;
}int Merge(int x,int y){
if(s[x].lz)Push_Down(x);
if(s[y].lz)Push_Down(y);
if(!x||!y)return x+y;
if(s[x].key<s[y].key)return s[x].rs=Merge(s[x].rs,y),Push_Up(x),x;
else return s[y].ls=Merge(x,s[y].ls),Push_Up(y),y;
}void Split(int now,int size,int &x,int &y){
if(!now)return x=y=,void();
Push_Down(now);
if(s[s[now].ls].sz>=size) y=now,Split(s[now].ls,size,x,s[now].ls);
else x=now,Split(s[now].rs,size-s[s[now].ls].sz-,s[now].rs,y);
Push_Up(now);
}inline void Insert(int val,int pos){
Split(root,pos-,x,y);
root=Merge(Merge(x,NewNode(val)),y);
}inline void Add(int l,int r,int val){
Split(root,r,x,z),Split(x,l-,x,y);
s[y].x+=val,s[y].lz+=val,s[y].sum+=val*s[y].sz;
root=Merge(Merge(x,y),z);
}inline int Query(int l,int r){
Split(root,r,x,z);Split(x,l-,x,y);
printf("%lld\n",s[y].sum);
root=Merge(Merge(x,y),z);
}signed main(){n=read();srand();
for(int x,i();i<=n;i++)x=read(),Insert(x,i);
int T=read();
while(T--){
int opt=read(),pos,l,r;
if(opt==)pos=read(),Insert(,pos);
if(opt==)l=read(),r=read(),pos=read(),Add(l,r,pos);
if(opt==)l=read(),r=read(),Query(l,r);
}return ;
}