since I have not written a tree-like array [cover face], new open a pit Qaqaq tree-like array
Tree-like array supports single-point modification + interval and query single-point modification + interval max-value query interval plus minus + single-point query
Query/modify interval max, query/modify interval and, single-point modification
Lowbit (a) =aand (−a) lowbit (a) =a and (a)
Definition c[i]=a[i−lowbit (i) +1]+...+a[i] C[i]=a[i-lowbit (i) +1]+...+a[i]
A picture of a tree-like array must be
We can find that for any one c[i] c[i], if modified, will affect the c[i+lowbit (i)] c[i+lowbit (i)], so each up and down, and then modify, (written in recursive form)
query [L,r] [l,r] sum sum, become sum[1,r]−sum[1,r] sum[1,r]-sum[1,r] One- dimensional single-point modification + interval maximum value query
For single point modification, modify C[i] to compare C[i−20],c[i−21]......c[i−lowbit (i) +1] C[i-2^0],c[i-2^1]......c[i-lowbit (i) +1]
Interval maximum value query, for an interval [l,r], if R-lowbit (r) +1 in [L,r] then take C[r-lowbit (R) +1,r] comparison, if not, then R to R-1
[Bzoj 1012] [JSOI2008] Maximum number of maxnumber one-dimensional interval plus and minus + single point query
We use the differential sequence to maintain the modified single-point modification of the interval interval, because the differential sequence sequence requires a prefix and a single point of query, the tree array of interval query is exactly the prefix and to achieve, so the tree number assembly is the value of the difference
Make d[i]=a[i]−a[i−1] d[i]=a[i]-a[i-1]
Single point query a[i]=∑ij=1d[j] a[i]=\sum_{j=1}^id[j]
Maintain d[i] with a tree-like array d[i] This sequence can be
[BZOJ1782] [Usaco2010 Feb]slowdown slowly swim one-dimensional interval plus minus + interval query
With the basis of a single point query, we'll look at the interval query
∑ni=1a[i]=∑ni=1∑