The idea of chunking is very common, which is to divide a series into k blocks and then manipulate them on the basis of blocks.
If the size of each block is magic, then the series of length n will be divided into ceil (n/magic) blocks altogether. This will have some nature:
1. The block number of the first series I is I/magic, which is the first i%magic in the block (although this one is useless).
2. If i%magic==0, stating that I is the beginning of block i/magic, the scope of section i/magic is [I/magic, (i+1)/magic).
The following is a block idea for an n-length sequence: Finds the maximum value of the sub-interval and modifies the value of a point.
1 Const intMAXN =50500;2 Const intMagic =Ten;3 intN, Q;4 intH[MAXN], B[MAXN];5 6 voidinit () {7 for(inti =0; I < n; i++) {8 if(i% Magic = =0|| H[i] > b[i/Magic]) {9B[i/magic] =H[i];Ten } One } A } - - intQueryintLintr) { the intRET =H[l]; - for(inti = l; I <=R;) { - if(i% Magic = =0&& i + Magic-1<=r) { -RET = max (ret, b[i/Magic]); +i + =Magic; - } + Else { ARET = max (ret, h[i++]); at } - } - returnret; - } - - voidUpdateintXintv) { inH[X] =v; - intL = x/magic *Magic; to intR = L +Magic; + for(inti = l; I < R; i++) { - if(i% Magic = =0|| H[i] > b[i/Magic]) { theB[i/magic] =H[i]; * } $ }Panax Notoginseng}
Block of interval processing