Lgc2012 @ 2024-09-01 08:49:03
#include<bits/stdc++.h>
using namespace std;
long long n,m,a[10000100],s[10000100],b,x,y,k;
int main(){
cin>>n>>m;
for(int i=1;i<=n;i++){
cin>>a[i];
s[i]=a[i]-a[i-1];
}
for(int i=1;i<=m;i++){
cin>>b;
if(b==1) {
cin>>x>>y>>k;
s[x]+=k;
s[y+1]-=k;
}
else {
long long sum=0,lx=0;
cin>>x>>y;
for(int i=1;i<=x;i++){
sum+=s[i];
lx+=s[i];
}
for(int i=x+1;i<=y;i++){
sum+=lx+s[i];
lx+=s[i];
}
cout<<sum<<endl;
}
}
return 0;
}
by CQ天神 @ 2024-09-01 09:02:07
@Lgc2012 我觉得用查分数组过不去喵,这边建议用线段树哦
by Lgc2012 @ 2024-09-01 09:16:42
线段树是什么,喵?
by companions @ 2024-09-01 10:44:35
@Lgc2012 建议去看“https://oi-wiki.org/ds/seg/”
by CommonDigger @ 2024-09-01 10:48:25
这是线段树算法的模板题目啊,本意就是要你用线段树做,用别的方法可能不一定可以ac @Lgc2012
by Lgc2012 @ 2024-09-01 10:58:24
(照样对差分数组不死心)
by leo120306 @ 2024-09-01 16:00:15
@Lgc2012 也可以用两个树状数组+差分解决
by Lgc2012 @ 2024-09-21 19:54:46
具体怎嘛做呢? @leo120306 ?
by Lgc2012 @ 2024-09-21 19:58:22
csp-j/s考完了,我又来了(话说这都20天前勒)
by leo120306 @ 2024-09-21 20:12:56
给你甩个链接吧