违规用户名920406 @ 2024-08-31 16:52:01
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll N=1e5+1;
ll n,m,p,b,c,d,a[N],T[N<<2],tag[N<<2];
inline ll ls(ll x) {return x<<1;}
inline ll rs(ll x) {return x<<1|1;}
inline void push_up(ll x) {T[x]=T[ls(x)]+T[rs(x)];}
inline void push_down(ll l,ll r,ll x)
{
ll m=(l+r)>>1;
a[ls(x)]+=tag[x]*(m-l+1);
tag[ls(x)]+=tag[x];
a[rs(x)]+=tag[x]*(r-m);
tag[rs(x)]+=tag[x];
tag[x]=0;
}
void bulid(ll l,ll r,ll x)
{
if(l==r)
{
T[x]=a[l];
return;
}
ll m=(l+r)>>1;
bulid(l,m,ls(x));
bulid(m+1,r,rs(x));
push_up(x);
}
void update(ll l,ll r,ll nl,ll nr,ll x,ll c)
{
if(nl<=l&&r<=nr)
{
T[x]+=c*(r-l+1);
tag[x]+=c;
return;
}
push_down(l,r,x);
m=(l+r)>>1;
if(nl<=m) update(l,m,nl,nr,ls(x),c);
if(nr>m) update(m+1,r,nl,nr,rs(x),c);
push_up(x);
}
ll query(ll l,ll r,ll nl,ll nr,ll x)
{
if(nl<=l&&r<=nr) return T[x];
push_down(l,r,x);
ll m=(l+r)>>1,c=0;
if(nl<=m) c+=query(l,m,nl,nr,ls(x));
if(nr>m) c+=query(m+1,r,nl,nr,rs(x));
return c;
}
int main()
{
cin>>n>>m;
for(int i=1;i<=n;i++)
cin>>a[i];
bulid(1,n,1);
while(m--)
{
cin>>p;
if(p==1)
{
cin>>b>>c>>d;
update(1,n,b,c,1,d);
}
else
{
cin>>b>>c;
cout<<query(1,n,b,c,1)<<endl;
}
}
return 0;
}
玄关
by Ke9_qux @ 2024-08-31 16:54:24
@buzhidao0123 push_down里面把T写成a了
by 违规用户名920406 @ 2024-08-31 16:55:19
谢谢爷
by 违规用户名920406 @ 2024-08-31 16:55:42
已关注
by 违规用户名920406 @ 2024-08-31 16:57:12
我超,还是错了
by 违规用户名920406 @ 2024-08-31 16:57:46
@Ke9_qux
by 违规用户名920406 @ 2024-08-31 16:59:54
样例输入:
5 5
1 5 4 2 3
2 2 4
1 2 3 2
2 3 4
1 1 5 1
2 1 4
样例输出:
11
14
26
by 违规用户名920406 @ 2024-08-31 17:00:40
@Ke9_qux @Ke9_qux @Ke9_qux @Ke9_qux @Ke9_qux
by 违规用户名920406 @ 2024-08-31 17:01:05
我超,还是错
by Ke9_qux @ 2024-08-31 17:01:13
@buzhidao0123 别急
by 违规用户名920406 @ 2024-08-31 17:04:29
%%%