@[wapmhac](/user/230875) 鬼畜的马蜂
by Durancer @ 2021-09-18 20:51:47
@[wapmhac](/user/230875) 你的 ask 的返回值没了??
by Durancer @ 2021-09-18 20:52:40
@[wapmhac](/user/230875)
```cpp
if(y<=mid) change(x,y,f,k<<1);
if(x>mid) change(x,y,f,k<<1|1);
```
Change 里面的这玩意没有理解错的话
你的 x, y 写反位置了
by Durancer @ 2021-09-18 20:53:54
qs
by Fan_Tuan @ 2021-09-18 20:54:09
@[Fan_Tuan](/user/371178) What are you doing?
by 2020121201a @ 2021-09-18 20:56:41
```cpp
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int MAX=4*1e5+10;
inline int read()
{
char qwqc=getchar();
int qwqf=1,qwqx=0;
while(qwqc<'0'||qwqc>'9')
{
if(qwqc=='-') qwqf=-1;
qwqc=getchar();
}
while(qwqc>='0'&&qwqc<='9')
{
qwqx=(qwqx<<3)+(qwqx<<1)+(qwqc^48);
qwqc=getchar();
}
return qwqf*qwqx;
}
struct node
{
int l,r;
int w,th;
}tree[MAX];
inline void bl(int l,int r,int k)
{
tree[k].l=l,tree[k].r=r;
if(l==r)
{
tree[k].w=read();
return ;
}
int mid=(l+r)>>1;
bl(l,mid,k<<1);
bl(mid+1,r,k<<1|1);
tree[k].w=tree[k<<1].w+tree[k<<1|1].w;
}
inline void down(int k)
{
tree[k<<1].th+=tree[k].th;
tree[k<<1|1].th+=tree[k].th;
tree[k<<1].w+=tree[k].th*(tree[k<<1].r-tree[k<<1].l+1);
tree[k<<1|1].w+=tree[k].th*(tree[k<<1|1].r-tree[k<<1|1].l+1);
tree[k].th=0;
}
inline int ask(int x,int y,int k)
{
if(tree[k].l>=x&&tree[k].r<=y)
{
// ans+=tree[k].w;
return tree[k].w;
}
if(tree[k].th) down(k);
int ans = 0;
int mid=(tree[k].l+tree[k].r)>>1;
if(x<=mid) ans += ask(x,y,k<<1);
if(y>mid) ans += ask(x,y,k<<1|1);
return ans;
}
inline void change(int x,int y,int f,int k)
{
if(tree[k].l>=x&&tree[k].r<=y)
{
tree[k].w+=(tree[k].r-tree[k].l+1)*f;
tree[k].th+=f;
return ;
}
if(tree[k].th) down(k);
int mid=(tree[k].l+tree[k].r)>>1;
if(x<=mid) change(x,y,f,k<<1);
if(y>mid) change(x,y,f,k<<1|1);
tree[k].w=tree[k<<1].w+tree[k<<1|1].w;
}
signed main()
{
int n=read(),m=read();
bl(1,n,1);
// for(int i=1;i<=4*n;i++)
// cout<<tree[i].w<<" ";
for(int i=1;i<=m;i++)
{
int pmh=read(),x=read(),y=read();
if(pmh==1)
{
int k=read();
change(x,y,k,1);
}
if(pmh==2) cout<<ask(x,y,1)<<endl;
}
return 0;
}
```
by Fan_Tuan @ 2021-09-18 20:56:43
@[2020121201a](/user/515970) ?
by Fan_Tuan @ 2021-09-18 20:57:03
@[wapmhac](/user/230875) 话说为啥宁可读入打快读
输出还用cout (
by Hencecho @ 2021-09-18 20:58:20
@[Fan_Tuan](/user/371178) Sorry!
by 2020121201a @ 2021-09-18 20:58:48
@[wapmhac](/user/230875) 话说建议把
```
k<<1|1
```
改成
```
((k<<1)|1)
```
by Hencecho @ 2021-09-18 21:01:25