new file: P3368.cpp

This commit is contained in:
hanyixuanten committed 2026-09-22 19:38:23 +08:00
1 parent 85dd254b3b
commit 893d0132f5
1 file changed
+43
+43
View File
@@ -0,0 +1,43 @@
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,m;
long long tree[500005];
long long a[500005];
int lowbit(int n){
return n&(-n);
}
void modify(int x,long long k)
{
for(;x<=n;x+=lowbit(x))
tree[x]+=k;
}
long long query(int x){
int ans=0;
for(;x;x-=lowbit(x))
ans=ans+tree[x];
return ans;
}
signed main(){
scanf("%lld%lld",&n,&m);
for(int i=1;i<=n;++i){
scanf("%lld",&a[i]);
modify(i,a[i]-a[i-1]);
}
while(m--){
int op;
scanf("%lld",&op);
if(op==1){
int x,y;
long long k;
scanf("%lld%lld%lld",&x,&y,&k);
modify(x,k);
modify(y+1,-k);
}else{
int x;
scanf("%lld",&x);
printf("%lld\n",query(x));
}
}
return 0;
}