// luogu-judger-enable-o2 #include <bits/stdc++.h> #define inf 500001 #define lll long long int using namespace std; long c[inf],a,n,m,k,xx,nn; int lowbit(int x){ return x&(-x);//求X二进制下从右到左第一个1的所对应的十进制下的值 } void update(int x,int y){//update添加修改之意 while(x<=n){ c[x]+=y;//c[i]树状数组 x+=lowbit(x); } } int sum(int x){ int sm=0; while(x>0){ sm+=c[x]; x-=lowbit(x);//注意顺序不能颠倒 } return sm; } int main(){ ios::sync_with_stdio(0); scanf("%d %d",&n,&m); for(int i=1;i<=n;i++) { scanf("%d",&a); update(i,a-nn); nn=a; } for(int i=1;i<=m;i++){ scanf("%d",&k); int aa,bb,cc; if(k==1){ scanf("%d %d %d",&aa,&bb,&cc); update(aa,cc); update(bb+1,-cc); } if(k==2){ scanf("%d",&aa); printf("%d\n",sum(aa)); } } return 0; }
原文地址:https://www.cnblogs.com/sc-pyt-2021-theworld/p/10426513.html
时间: 2024-10-10 11:56:58