A tree-shaped array of templates, modifying the values of the entire interval (plus x), querying a node, showing a non-differential method
1#include <cstdio>2#include <cctype>3 using namespacestd;4 5 intc[500010],n,m,a[500010];6 7 intRead ()8 {9 intx=0, f=1;Ten CharC=GetChar (); One while(!IsDigit (c)) Af=c=='-'?-1:1, c=GetChar (); - while(IsDigit (c)) -X= (x<<1) + (x<<3) + (c^ -), c=GetChar (); the returnx*F; - } - - intLowbit (intx) + { - returnx&-x; + } A at intQueryintx) - { - intans=0; - for(; x;x-=lowbit (x)) -ans+=C[x]; - returnans; in } - to intUpdateintXintval) + { - for(; x<=n;x+=lowbit (x)) thec[x]+=Val; * } $ Panax Notoginseng intMain () - { the inti,j,t,p; +N=read (), m=read (); A for(i=1; i<=n;i++) thea[i]=read (); + while(m--) - { $t=read (); $ if(t==1) - { -I=read (), J=read (), p=read (); the Update (I,P); -Update (j+1,-p);Wuyi } the Else - { Wup=read (); -printf"%d\n", a[p]+query (P)); About } $ } - return 0; -}
Tree-like array template 2--interval modification, single point query