Tree-like array interval modification &&**......*&%&
Well, I looked at Running-coder's blog for a long while to understand ...
Not much nonsense said: "Talk about ideas: no ......."
Code:
1#include <cstdio>2#include <iostream>3#include <cmath>4#include <algorithm>5 using namespacestd;6 intbit[1000000],n,m,d,p,xx,yy,kk;7 intlazy[1000000];8 inta[1000000];9 Ten voidAddintIintx) { One while(i<=N) { Abit[i]+=x; -I+=i &-i; - } the } - - voidADDN (intXintYintk) { - while(y>=x) { +lazy[y]+=K; -Y-=y &-y; + } Ax--; at while(x>y) { -lazy[x]-=K; -X-=x&-x; - } - } - in intSuminti) { - ints=A[i]; to while(i<=N) { +s+=Lazy[i]; -I+=i &-i; the } * returns; $ }Panax Notoginseng - intMain () { thescanf"%d%d",&n,&m); + for(intj=1; j<=n;j++){ Ascanf"%d",&d); the Add (j,d); +a[j]=D; - } $ for(intj=1; j<=m;j++){ $scanf"%d",&p); - Switch(p) { - Case 1:{ thescanf" %d%d%d",&xx,&yy,&KK); - Addn (XX,YY,KK);Wuyi Break; the } - Case 2:{ Wuscanf"%d",&xx); -Cout<<sum (XX) <<Endl; About Break; $ } - } - } - return 0; A}
Tree-like array 2 template Luogu 3368